Re: Send XML file with curl functions

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

 




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=@xxxxxxxxxx" "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@xxxxxxxxxxxx

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




What I can suggest
1. save the XML to file eg xmldata.xml   and use
system('curl -F "data=@xxxxxxxxxxx" "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/





[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