I could not get posted data with $HTTP_RAW_POST_DATA

liunx

Guest
Hello all there,
I have this code in client part:

$strRequest = "
<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<tracking>
<ac-info>
<ac-uid>10010</ac-uid>
<ac-pid>1</ac-pid>
<ac-username>rajug</ac-username>
<ac-password>mypwd</ac-password>
</ac-info>
<item>
<itemid>PRD-12001</itemid>
<itemname>Processor</itemname>
<itemprice>555</itemprice>
<itemqty>2</itemqty>
</item>
<item>
<itemid>PRD-12002</itemid>
<itemname>Hard Drive</itemname>
<itemprice>300</itemprice>
<itemqty>2</itemqty>
</item>
<item>
<itemid>PRD-12003</itemid>
<itemname>Monitor-Samsung</itemname>
<itemprice>410</itemprice>
<itemqty>5</itemqty>
</item>
</tracking>";

$url = "http://www.mydomain.com/xml_parse.php";

$header[] = "HOST: <!-- w --><a class="postlink" href="http://www.mydomain.com">www.mydomain.com</a><!-- w -->\r\n";
$header[] = "MIME-Version: 1.0\r\n";
$header[] = "Content-type: multipart/mixed;boundary=----doc\r\n";
$header[] = "Accept: text/xml\r\n";
$header[] = "Content-length: " . strlen($strRequest) . "\r\n";
$header[] = "Cache-Control: no-cache\r\n";
$header[] = "Connection: close \r\n";
$header[] = $strRequest;



$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

$data = curl_exec($ch);
if(curl_errno($ch)){
print curl_error($ch);
}
else{
curl_close($ch);
echo $data;
}

And my server part, i have used this code:

$somecontent = $HTTP_RAW_POST_DATA;
$somecontent = trim(str_replace('----doc', '', $somecontent));

echo $somecontent;

I have borrowed this sample or example codes from <!-- m --><a class="postlink" href="http://us2.php.net/curl">http://us2.php.net/curl</a><!-- m -->.
when i run the client side file from client server, it just shows the 1 as a result. How can i get that XML sent from client? Please help me, i am trying to do this for a long time but i could not do this.

Thank you very much in advance for the help.There are a couple of user notes on the curl_exec page that may be relevant to you: if you get a zero-sized response, for some reason, curl_exec() returns true ("1") instead of an empty string. The suggestions in those posts may help.
(Also, consider making the request yourself and seeing what you get back.)
 
Back
Top