POST response is missing location Header field

Hi,
I’m doing a POST to harvest.com to create a project. The project is created, but the Response is supposed to include the location of the new project in the field Location. The problem is, I can’t get that field, even though it appears to be one of the standard fields.

My code:

[php]
$credentials = “myemail:mypassword”;

$xml_data = ’
suprolapsteel
true
none

94687



none
’ ;

$url = “http://fullcity.harvestapp.com/projects”;

$headers = array(
“Content-type: application/xml”,
“Accept: application/xml”,
"Authorization: Basic " . base64_encode($credentials)
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, “Worksmart_Havest_Connector”);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);

$response = curl_exec($ch);

if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else {
// Show me the result
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);
}
[/php]

I get an array that includes status 201 and a bunch of standard fields, but no Location field. Tech support confirmed that they get the Location when doing straight CURL.

Is there some other approach I can try? I should mention that I modified a sample script to do this. Unfortunately I’m very new to php and know even less curl.

Thanks,
-jb

OK,
so I studied the options under curl_setopt, and realized I must need CURLOPT_HEADER. So I added “curl_setopt($ch, CURLOPT_HEADER, 1);” and sure enough, “var_dump($response);” gives me the header as text, and includes the location field. Whereas “$info = curl_getinfo($ch); var_dump($info);” Gave me the header formatted as an array and excluding the location field. All is now well.

Sponsor our Newsletter | Privacy Policy | Terms of Service