How to call webservice in php?
August 22, 2014
pateldivya
Blog, PHP
(0 Comments)
I have called web services in php by using curl function. In below I have given one example. I have sent XML Request by using curl function.Because My web services return data on XML Format.
$xml_data = ''; //pass parameter using XML request provide By webservices
$postData = array( // You can pass parameter using Array and pass in postfields.
'authId'=>'',
'siteId'=>'',
'countryId'=>'',
'regionId'=>'',
'weekType'=>'',
'startDate'=>''
);
$URL = "http://www.yourwebservices.com/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
After that Load XML data using DOM Document in php
$doc = new DOMDocument();
$doc->loadXML($output);
Finally retrieve data by using XML Tag Name.
//count is Tag name of XML.
echo $count = $doc->getElementsByTagName('count')->item(0)->nodeValue;
Leave a Comment
You must be logged in to post a comment.