libcurl - Getting BAD Request with CURL in PHP POSTING XML DATA -
i using php curl post xml data server using ip, fullfilled requirements making work, still getting error of "bad request". have on code below.
$var2 ="<doc><item>some content.</item></doc>"; $url = "server ip"; $header = "post http/1.1 \r\n"; $header .= "content-type: text/xml \r\n"; $header .= "content-length: ".strlen($var2)." \r\n"; $header .= "content-transfer-encoding: text \r\n"; $header .= "connection: close \r\n\r\n"; $header .= $var2; $ch = curl_init(); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); curl_setopt($ch, curlopt_url,$url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_timeout, 4); curl_setopt($ch, curlopt_postfields, $var2); curl_setopt($ch, curlopt_customrequest, $header); // response $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($ch); echo $data;
need asap.
thanks
first, using request-line :
$header = "post http/1.1 \r\n";
according http 1.1 rfc, **request-line**
should :
request-line = method sp request-uri sp http-version crlf
so, seems should add uri between post
, http/1.1
(but, before coding that, read i've written in next paragraphs of answer)
then, passing lot of things curlopt_customrequest
.
i don't think can pass header using option (quoting) :
valid values things "
get
", "post
", "connect
" , on;
i.e. not enter whole http request line here.
for instance, entering "get /index.html http/1.0\r\n\r\n
" incorrect.
if want specify custom headers (it seems do), should use curlopt_httpheader
option, instead of curlopt_customrequest
(quoting documentation of first one) :
an array of http header fields set, in format
array('content-type: text/plain', 'content-length: 100')
Comments
Post a Comment