XML : PHP CURL PUT Equivalent to Command Line

I am working on a PHP webservice that will be making REST calls to an application API. My webservice is built on a LAMP server running ubuntu and the following command is working perfect from command line:

curl -k -u username -H "Content-type: application/xml" -d @request.xml https://server/path/

However, when I try to build the same request in PHP I am getting the following response from the REST server, indicating that the XML is missing:

HTTP400Premature end of file.

Here is the code of my PHP request:

  $ch2 = curl_init($service_url);  $headers = array('Content-Type: application/xml', 'Accept: application/xml');  curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);  curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0);  curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0);  curl_setopt($ch2, CURLOPT_PUT, 1);  curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "PUT");  curl_setopt($ch2, CURLOPT_POSTFIELDS, $xmlRequest);  curl_setopt($ch2, CURLOPT_USERPWD, 'user:password');  $curl_response = curl_exec($ch2);    

Everything I have read indicates the CURLOPT_POSTFIELDS is the place to do this, but I thought this was for adding "?" variables to the actual URL. Anyway, any help would be appreciated.

No comments:

Post a Comment