Tuesday, 17 September 2013

How does this curl command differ from my php code?

How does this curl command differ from my php code?

I am simply trying to duplicate this curl command in PHP:
curl -X POST -H 'Content-Type: application/xml' -u username:password
https://api.company.com/api/path
This is the PHP code I am using:
$ch = curl_init("https://api.company.com/api/path");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch); // $response is null
$info = curl_getinfo($ch); // $info['http_code'] is 400
While my shell command is successful and I get data back from the server,
this PHP code fails -- the server returns a 400 error. As far as I know,
the PHP code and the shell command are effectively identical, so what's
the difference I am missing?

No comments:

Post a Comment