Re: Best way to post XML via curl?
| From: | Stuart | Date: | Thu, 12 Feb 2009 00:56:21 +0000 |
| Subject: | Re: Best way to post XML via curl? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288135@lists.php.net to get a copy of this message | ||
2009/2/12 Brian Dunning <brian@briandunning.com>:
> 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 & and &.... is there
> a "best practice" for how a big block of xml should be posted?
-Stuart
--
http://stut.net/