Re: reading incoming xml

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

 



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

> 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'<https://myserver/mytestpage.php%27>
> );
> 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.


hmm,  it looks to me like you want to post a bunch of raw data to the
server.  im not sure exactly how to do that w/ the php curl functions...
everything ive seen uses CURLOPT_POSTFIELDS to supply an associative array
of data to be posted.  in this case you could easily send you data across by
choosing a name for the index, something like 'postdata', anything will do,
then it will be accessible on the system youre posting to via
$_POST['postdata'].

also, inlooking at your usage of CURLOPT_CUSTOMREQUEST, i dont believe youre
using it correctly,  i think youre just supposed to put a string
representing the desired http method in there, so something like 'HEAD',
'PUT', or in this case 'POST'.  then you would supply the data as i said
earlier, using CURLOPT_POSTFIELDS.  so in all, i think something like this
would work for you,

$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'<https://myserver/mytestpage.php%27>
> );
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_TIMEOUT, 4);
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

curl_setopt($ch, CURLOPT_POSTFIELDS, array('postdata' => $message));

>
> $data=curl_exec($ch);


and also, in reading the warning about CURLOPT_CUSTOMREQUEST, you might just
go with CURLOPT_POST => true, since you arent using an obscure http method.
im not sure exactly how to determine if the server supports this method or
not.  anyway, i found this in 'man curl_easy_setopt'  (thats the manpage for
the c function php uses for the CURLOPT_CUSTOMREQUEST option).

              Many people have wrongly used this option to replace the
entire request with their own, including multiple headers and POST contents.
While that  might
              work  in  many  cases,  it will cause libcurl to send invalid
requests and it could possibly confuse the remote server badly. Use
CURLOPT_POST and CUR-
              LOPT_POSTFIELDS to set POST data. Use CURLOPT_HTTPHEADER to
replace or extend the set of headers sent by libcurl. Use
CURLOPT_HTTP_VERSION  to  change
              HTTP version.

-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