Re: reading incoming xml

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

 



On Sat, Mar 1, 2008 at 4:12 PM, Larry Brown <
larry.brown@xxxxxxxxxxxxxxxxxxxxx> wrote:

> I am running apache with php.  I set up a curl script to send an xml
> request to the php page


did you use a request header to somehow set a mime type to indicate youre
looking for xml?  could you show us this request, im not sure how to request
for xml specifically..


> My $_POST array is empty though.


 is this on the system where the xml will be sent from?  you have to
populate the post fields in the request by using the curl option
CURLOPT_POST to indicate you are posting, and CURLOPT_POSTFIELDS, to pass an
array of parameters that will be used as post fields.  then the $_POST array
will be populated on the provider system.

 Is there some other
> place I should be looking?  $_SERVER shows the incoming message as a
> post but again the data isn't there.


still curious if youre looking on the consumer (system sending curl request)
or the provider, (system providing the xml data via response).


>  Does apache/php place the xml in
> some other location for me to access?
>

depending on how you configure curl, the data can be in different places.
the easiest way (i think) is to use the CURLOPT_RETURNTRANSFER option.  then
the response will be returned from curl_exec() (rather than a boolean
success flag).

here is sample code from a consumer and a provider; theyre up on my server
so you can try using the consumer if you want.

CONSUMER
-------------------
<?php
$curlHandle = curl_init('http://nathan.moxune.com/postXml.php');
curl_setopt_array($curlHandle, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        'token' => 1
    )
));

$response = curl_exec($curlHandle);
if(!empty($response)) {
    try {
        $sxml = new SimpleXmlElement($response);
        echo $sxml->asXML();
    } catch(Exception $e) {
        die($e->getMessage());
    }
}
?>

PROVIDER
-----------------
<?php
if($_POST['token'] == 1) { ?>
<someString>
    <moreHere>
        <lessHere />
    </moreHere>
</someString>
<?php } ?>

-nathan

[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