RE: Having problem sending XML over HTTP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Nauman Akbar [mailto:naumanakbar78@xxxxxxxxx] On Behalf Of Nauman
> Akbar
> Sent: Thursday, December 14, 2006 3:32 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Having problem sending XML over HTTP
> 
> Hello!
> 
> 
> 
> I picked up an example from Curl section on php.net. I am able to access
> the
> remote page fine with a custom header. Unfortunately, I am not able to
> retrieve the XML I am sending at the remote end. I have tried both
> $HTTP_RAW_POST_DATA and php://input but neither of them returns anything.
> I
> am putting my code below just in case anyone can point out the problem in
> there.
> 
> 
> 
> $xmlstr = <<<XML
> 
> <query>
> 
>             <username>fff-bbbb</username>
> 
>             <password>alphanumeric</password>
> 
>             <function>GetPackageVersion</function>
> 
> </query>
> 
> XML;
> 
> 
> 
> $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($xmlstr)." \r\n";
> 
> $header[] = "Cache-Control: no-cache";
> 
> $header[] = "Connection: close \r\n\r\n";
> 
> $header[] = $xmlstr;
> 
> 
> 
> print("setting url<BR>");
> 
> $request = curl_init("http://mrcod.concisehosting.com/index.php";);
> 
> print("setting options<BR>");
> 
> curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
> 
> curl_setopt($request, CURLOPT_TIMEOUT, 4);
> 
> curl_setopt($request, CURLOPT_HTTPHEADER, $header);
> 
> curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'POST');
> 
> 
> 
> print("connecting...<BR>");
> 
> $response = curl_exec($request);
> 
> //curl_exec($request);
> 
> curl_close($request);
> 
> print($response);
> 
> 
> 
> I have checked the ini file. Memory reserved for POST is 8M. Moreover, I
> even tried turning 'always_populate_http_raw_post_data' but it doesn't
> work.
> Any one any ideas, I am in real need for help on this.
> 
> 
> 
> Regards
> 
> Nauman Akbar
> 
> Concise Solutions


Try this:

--------------------------------
The code for the sending script:

<?php
$xmlstr =
"<query><username>fff-bbbb</username><password>alphanumeric</password><funct
ion>GetPackageVersion</function></query>";

$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://example.com/your-accepting-page.php";);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlstr=".urlencode($xmlstr)); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$buffer = curl_exec($ch); 
curl_close($ch);

print_r($buffer);
?>

----------------------------------
The code for the receiving script:

<?php

if(!empty($_POST)) {
	echo "You sent me some data... here is what I received:\n";
	print_r($_POST);
}

?>

Then open a browser and surf to the sending script.  It should print the
response from the receiving page.

Here is the output:

You sent me some data... here is what I received:
Array
(
    [xmlstr] =>
<query><username>fff-bbbb</username><password>alphanumeric</password><functi
on>GetPackageVersion</function></query>
)

I tested this and its working (at least on my server).

Sorry I don't have the time to tell you what is wrong with your code but
it's easier for me to just provide something that works.

I hope that helps you,

Brad

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux