Jump to content

[SOLVED] How to attach POST data to CURL...???


angelleye

Recommended Posts

I'm trying to use CURL to submit XML requests to web service API's.  I've got everything working except that I can't figure out how to actually attach my own custom XML string request to the POST.  As such, I'm getting XML responses that simply say 'Invalid Request'.  Here's what my CURL function currently looks like:

 

function CURLRequest($xmlRequest)
{

	$curl = curl_init();
			curl_setopt($curl, CURLOPT_VERBOSE, 1);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($curl, CURLOPT_TIMEOUT, 120);
			curl_setopt($curl, CURLOPT_URL, $this -> EndPointURL);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	//execute the curl POST and then clean out the bad line in the response.
	$xmlResponse = curl_exec($curl);

	curl_close($curl);

	return $xmlResponse;

} //End CURLRequest function

 

What do I need to add to the CURL options in order to include the XML data with the POST?  Any information would be greatly appreciated. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/55482-solved-how-to-attach-post-data-to-curl/
Share on other sites

You need the:

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $param);

 

where $param is a string of 'var1=value1&var2=value2&var3=value3'

 

Of course the variables are those required by the url you are trying to post. The value might be your xml file (or xml strings).

 

Read CURL explanation from php.net to get examples.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.