0

Hello everyone,

I am using the following code to do a post to localhost:

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/response.php');
//response.php just spits out json_encode($_POST)
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/html"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, Array('data' => $xml));
$curl_result = curl_exec($ch);
if(curl_errno($ch)) {
	echo 'Curl error: '.curl_error($ch);
}
curl_close($ch);
echo $curl_result;
//Outputs []

As stated in the comment, nothing gets posted to the server. What am i doing wrong?:confused:
BTW: If i change Array('data'=>$xml) to simply $xml (which is a string constructed previously) it stops working altogether (just as if a syntax error occurred).
Thanks !

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by TotoTitus
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.