I'm trying to send a cXML response message to a URL via http post using curl. The context of it all is I receive a cXML 'request' message via http post, validate it, parse it, and send back a cXML response message. I put the cXML response message in a string variable. The testing environment i'm using gives only vague error messages (i.e. 'No response received'). I know that I successfully receive, validate and parse the incoming request cXML message because I put a mail() function in that emails me the variable values of the parsed cXML. It must be the http post of the cXML response back that is dysfunctional. I have tried several variations but continue to receive the same error message 'No response recieved'. The code I'm using now is below:
Code: Select all
$response = urlencode($response);//url encode the cXML string
$length = strlen ($response);//get the length of the cXML string
$post = array("Host: http://www.someplace.com", "Content-Length: $length", "Content-Type: text/xml", "Connection: Close");
// Send using CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $response); // post the cXML string stored in variable
curl_setopt( $ch, CURLOPT_TIMEOUT, 500 );
curl_exec ($ch);
curl_close ($ch);
Any ideas. Thanks.