cURL error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bhaynes
Forum Newbie
Posts: 3
Joined: Thu Apr 08, 2010 3:01 pm

cURL error

Post 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);
Last edited by Benjamin on Sun Apr 11, 2010 10:45 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: cURL error

Post 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.
bhaynes
Forum Newbie
Posts: 3
Joined: Thu Apr 08, 2010 3:01 pm

Re: cURL error

Post 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!
Post Reply