RE: Having problem sending XML over HTTP

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

 



Hello!

Thanx for reminding me that I can use a regular POST as well rather then
sending XML over HTTP directly :). Perhaps I was quite tired by then.

Anyways I tried that. Unfortunately, it seems POST data is not getting
through at all. I sent the same query with GET and it is returned fine. But
var_dump on both $_POST and $HTTP_RAW_POST_DATA return empty strings even
with a regular POST with Curl. Yes the data is urlencoded.

My server is RHEL4 with Plesk 8.x. I got PHP upgraded to PHP 5 yesterday. I
know POST requests are working fine through browser. I have tried Opera and
IE and both work just fine. So my guess is; it is probably curl causing the
problem. Can someone point me to some resource or documentation on this
issue?

Regards,
Nauman Akbar
Concise Solutions

-----Original Message-----
From: Brad Fuller [mailto:bfuller@xxxxxxxxxxxxxxxx] 
Sent: Friday, December 15, 2006 2:16 AM
To: php-general@xxxxxxxxxxxxx
Subject: RE:  Having problem sending XML over HTTP

> -----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

-- 
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