Re: Send XML file with curl functions
| From: | Bojan Tesanovic | Date: | Sun, 13 Apr 2008 03:53:42 +0000 |
| Subject: | Re: Send XML file with curl functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272953@lists.php.net to get a copy of this message | ||
On Apr 12, 2008, at 11:37 PM, Aaron Axelsen wrote:
I am trying to create the following command with the php curl functions: curl -F "data=@domain.xml" "http://path/to/api" The problem i'm having is that i'm creating the xml file with php - so the contents are stored in a variable. How can I send the contents of that variable via curl? I thought just assigning the xml variable to data would work - but it hasn't. Any suggestions? --Aaron Axelsen lists@frozenpc.net Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpWhat I can suggest 1. save the XML to file eg xmldata.xml and use system('curl -F "data=@xmldata.xml" "http://path/to/api" '); 2. or Use PHP CURL functions fufunction postData($postFileds,$url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST ,1); curl_setopt($ch, CURLOPT_POSTFIELDS ,$postFileds);curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL$data = curl_exec($ch); curl_close($ch); return $data; } $xmlData = 'some xml data'; $postFileds = 'data='. urlencode($xmlData); //call function postData($postFileds,"http://path/to/api"); ------- Bojan http://www.carster.us/