Page 1 of 1

cURL error

Posted: Sat Apr 10, 2010 9:23 pm
by bhaynes
I'm trying to post an xml string to an external url using cURL. I'm getting a 400 Bad Request error. Can someone let me know if there's something wrong with this cURL request or if I'm missing something? Note that I was getting a connection failed error until I added the CURLOPT_PROXY line below. Now I'm getting the 400 error.

Code: Select all

$header = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n";
$header .= $post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_PROXY,"localhost:80");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

$data = curl_exec($ch);
print $data; 

if(curl_errno($ch))
print curl_error($ch);
else
curl_close($ch);

Re: cURL error

Posted: Sun Apr 11, 2010 4:53 am
by requinix
Either you write the request yourself (which is what you did with $header) or you use cURL. Don't mix and match the two.

Re: cURL error

Posted: Sun Apr 11, 2010 8:08 am
by bhaynes
If it's an easy fix can you show me how this would alter my code? Or if I were to remove the request how would I pass my xml string variable using cURL? Thanks for the assistance!