Re: reading incoming xml

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

 



I'm sending from a php cli with:

$post = '<?xml version="1.0"
encoding="UTF-8"?><Data>'.$vendorCompanyID.'</Data>';

$message = generatePage($page, $post);	
      
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://myserver/mytestpage.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $message);

$data=curl_exec($ch);


I've the server page (mytestpage.php) set up as:

echo "hello\n";

print_r($_SERVER);

where I replace SERVER with POST etc and I can't find the string '<?xml
version="1.0" encoding="UTF-8"?><Data>'.$vendorCompanyID.'</Data>' in
the $data output.  I do get the hello so I know I am hitting the server
and when it is set to $_SERVER as listed above I get the expected array
but $_POST is empty.

Larry

On Sat, 2008-03-01 at 16:59 -0500, Nathan Nobbe wrote:
> 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
-- 
Larry Brown <larry.brown@xxxxxxxxxxxxxxxxxxxxx>

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