Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.