Re: Best way to post XML via curl?

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

 



2009/2/12 Brian Dunning <brian@xxxxxxxxxxxxxxxx>:
> I'm going crazy, can't quite get this encoding to work. I've tried all the
> various combinations, trying to send this block $xml (which is a simple
> string variable) via post along with 3 other params:
>
> $postArgs = http_build_query(array('method'=>'newPrintRequest',
> 'login'=>$login, 'password'=>$password, 'orderxml'=>$xml));
> $ch = curl_init('http://test.server.com/rest_interface.php');
> curl_setopt($ch, CURLOPT_POST, true);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs);
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));

Drop the above line and I reckon it should work. The content you're
sending is not XML, it's form fields which CURL will default to. It
just happens that one of those fields is XML.

> $response = curl_exec($ch);
>
> Is this use of http_build_query the best way to send XML? Any other curl
> options I should be setting? I tried urlencoding() the $xml, I tried
> htmlspecialchars(), I tried nothing at all, I tried &amp and &.... is there
> a "best practice" for how a big block of xml should be posted?

-Stuart

-- 
http://stut.net/

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