Take the 2-minute tour ×

I am not that experienced with cURL and I have spent a couple of days trying to sort this problem: I have an issue with cURL not appending the query string to my URL in the headers when I submit a POST request; hence no 'payload' is received by the server and I get returned an error status code by the service I'm accessing which indicated it didn't receive the appropriate data.

I think the POST should start with the full domain name, but I'm not sure. If I'm posting data, shouldn't Content-Length be '0' instead of what I am getting?

The outgoing header looks like this:

POST /rest/v1/oliver/groups/ORIGINNUMBER/member? HTTP/1.1
Accept: application/xml
Content-type: text/plain
User-Agent: Custom PHP Script
Host: campaign.oventus.com
Content-Length: 95

My php code looks like this:

$fields_string = "firstName=$fname&amp;secondName=$sname&amp;password=$pass&amp;deviceAddress=$phonenumber&amp;notes=testing";

$url = "http://campaign.oventus.com/rest/v1/ACCOUNTNAME/groups/ORIGINNUMBER/member?";

  $header[] = "Accept: application/xml";
  $header[] = "Content-type: text/plain";
  $header[] = "User-Agent: Custom PHP Script";
  $header[] = "Host: campaign.oventus.com";
  $header[] = "Cookie: ".$cookie;

$cx = curl_init();
    curl_setopt($cx, CURLOPT_URL,$url);
    curl_setopt($cx, CURLOPT_POST, 5);
    curl_setopt($cx, CURLOPT_POSTFIELDS,$fields_string);
    curl_setopt($cx, CURLOPT_HTTPHEADER, $header);
    curl_setopt($cx, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($cx, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($cx, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cx, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($cx, CURLOPT_TIMEOUT, 15);
    curl_setopt($cx, CURLOPT_HEADER, 1);
    curl_setopt($cx, CURLINFO_HEADER_OUT, TRUE);
$final = curl_exec($cx);
$errors = curl_error($cx);
$errornos = curl_errno($cx);

$headcut2 = explode ("n/xml", $final);
$headstring2 = $headcut2[0]."n/xml";
$xmlstring2 = $headcut2[1];

    echo "<h2>Add to Group result: </h2>";
    echo "<p>RAW header: <code>$final</code></p>";
    //echo "<p>Response header: <code>".htmlentities($headstring2)."</code></p>";
    echo "<p>XML response: <code>".htmlentities($xmlstring2)."</code></p>";
    //echo "<p>".print_r($info)."</p>";
    //echo "<p>CURL info: $info</p>";
    //echo "<p>Curl error: $errors</p>";
    echo "<p>Curl error num: $errornos</p>";

    print "<pre>\n";
    print_r(curl_getinfo($cx));  // get error info
    print "</pre>\n";


And the header returned by the server is this:

HTTP/1.1 200 OK Date: Fri, 26 Aug 2011 17:30:12 GMT 
Server: Apache/2.2.17 (Unix) DAV/2 Content-Length: 144 
X-Powered-By: Servlet/2.5 JSP/2.1 Cache-Control: no-store, no-cache 
Vary: Accept-Encoding,User-Agent Pragma: no-cache 
Content-Type: application/xml 202

With the returned XML:

<status xmlns="http://jaxb.rest.pageone.com" description="No Devices to add">202</status>

As far as I can tell, I'm definitely hitting the server, but it doesn't seem to receive the data I'm sending it..

Stumped. Hope someone can point me in the right direction!


share|improve this question
Everything I was doing was fine, but the REST service wasn't functioning properly. Bug was fixed their end and it all worked out fine. grr. –  oliver Nov 21 '11 at 17:08

2 Answers 2

Looks like your hitting the server, and likely the data is going to... I think the answer lies in 202:No Devices to add... which the REST interface documentation should explain (perhaps you're missing a required field?) {202 FYI means accepted but no processing was completed, could also mean the user exists}

By the way you should be escaping those arguments you're putting into the POST payload ($fname,$sname,$pass,$phonenumber)... otherwise a weird value (say name) could cause the post to act completely differently to the way you expected. You can do that using urlencode, or by instead building the POST string with http_build_query

share|improve this answer
Thanks for your reply. The documentation doesn't go in to enough detail unfortunately. But you are sure that the post data is actually getting through? –  oliver Aug 30 '11 at 7:57
Well no, I can't be sure with out knowing more about the system and the documentation, but there's no reason the data shouldn't get posted to the remote server (whether it's throwing it away is another story). Best way around is to create a local test.php that simply logs the contents of POST to a file (<?php file_put_contents("post.log",print_r($_POST,true));exit();?> and then change your URL to the local page and see what shows up in the log. –  Rudu Aug 30 '11 at 16:47
Turned out this was actually a problem with the REST service I was using - it was miss-handling my request. –  oliver Nov 21 '11 at 17:02

curl_setopt($cx, CURLOPT_POST, 5); is set to 5 should be bool. http://php.net/manual/en/function.curl-setopt.php

share|improve this answer

Your Answer


