http - How to send a cURL POST without request data in PHP? -


my goal send post request server , proper response.

note: angled brackets represent placeholders.

in terminal, using following code provide me desired response.

curl -u <user>:<pass> -h 'content-type: application/xml' -x post https://<rest of url> 

my current php looks this:

$ch = curl_init(); curl_setopt($ch, curlopt_url, $uri); //$uri same use in terminal curl_setopt($ch, curlopt_userpwd,     sprintf('%s:%s', $user, $pass)); //same terminal user & pass curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_ssl_verifypeer, false); $headers = array(     'content-type: application/xml', //expect xml response ); curl_setopt($ch, curlopt_httpheader, $headers); $curl_result = curl_exec($ch); 

using php, 400 bad request error.

the verbose information:

> post <same url> http/1.1 authorization: basic ywrtaw5ac3bhcms0nteuy29tonnwyxjrc29tzxroaw5n host: <correct host> accept: */* content-type: application/xml content-length: -1 expect: 100-continue  * http 1.0, assume close after body < http/1.0 400 bad request < cache-control: no-cache < connection: close < content-type: text/html 

why getting 400 bad request error when use php, not when use command line? how can fix issue desired response using php?

curl_setopt($ch, curlopt_postfields, array()); 

after adding line, resolved problem. in way, solution makes sense; don't understand why curlopt_postfields required. in php documentation, part should included under curlopt_post, unless accidentally works.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -