I have a very simple php curl application where below is my codes I used to send header and body to server.
<?php
$xml_data = "<Request><NewOrder>";
$URL = "http://localhost/rece1.php";
$header ="";
// Build header as array for cURL option
$header = "HTTP/1.0\r\n";
$header.= "MIME-Version: 1.0\r\n";
//$header.= "Content-type: application/PTI46\r\n";
$header.= "Content-length: ".strlen($xml_data)."\r\n";
$header.= "Content-transfer-encoding: text\r\n";
$header.= "Request-number: 1\r\n";
$header.= "Document-type: Request\r\n";
$header.= "Interface-Version: Test 1.4\r\n";
$header.= "Connection: close \r\n\r\n";
$header.= $xml_data;
// Define cURL options, then connect to server while saving response
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$f = fopen('request.txt', 'w');
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_STDERR ,$f);
$rawResponse = curl_exec($ch);
echo "TEST : ".$rawResponse;
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
?>
At the server end (rece1.php) I have this.
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}
?>
What I get the results is Empty reply from server. I would like to receive the header information back from server with the body formatted in certain format which some ack message. How can I achieve that?