February 03 2013

PHP use curl post xml

Tagged Under :

Because I want integrate my web application with one of the famous payment gateway. But they didn’t provide any API and just give the documentation only.

So I write the code myself to communicate the payment gateway server.

First, prepared the XML format what I want. and give a variable name $xml
Example XML:
		<child>child 1</child>
		<child>child 2</child>
After that, use the php code below to post the xml to that server. and please made sure the url is correct.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8", 'Content-Length: '.strlen($xml)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "http:\\www.chevronscode.com\");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));

Make a Comment

You must be logged in to post a comment.