Thursday 22 November 2018

How to save responose of cURL to XML file

Here Explain about how to save response of curl to xml file, follow the snippet of code
      $path = "http://www.abc.com";
      $user_agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";

 $in_curl = curl_init();
 curl_setopt($in_curl, CURLOPT_URL, $path);
 curl_setopt($in_curl, CURLOPT_POST, 0);
 curl_setopt($in_curl, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($in_curl, CURLOPT_HEADER, false);
 curl_setopt($in_curl, CURLOPT_USERAGENT,$user_agent);
 curl_setopt($in_curl, CURLOPT_CONNECTTIMEOUT , 30);
 curl_setopt($in_curl, CURLOPT_TIMEOUT, 5);
 curl_setopt($in_curl, CURLOPT_SSL_VERIFYPEER, false);# required for https urls
 
 $resultxml = curl_exec($in_curl);
 $status = curl_getinfo($in_curl);
 
 curl_close($session);

 if (file_put_contents ('./responsedata.xml', $resultxml) !== false) {
      echo 'Success!';
 } else {
      echo 'Failed';
 }

No comments:

Post a Comment