Home » Php » php – Curl return response is being empty

php – Curl return response is being empty

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to send xml soap request to get response of soap i tested on SoapUI i could get response there but when doing same thing on my php web page its giving empty response.

$url = 'https://osbtest.epg.gov.ae/ebs/genericapi/lookups';
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epg="http://epg.generic.masterdata/">
<soapenv:Header/>
<soapenv:Body>
  <epg:GetCountriesRequest>
     <!--Optional:-->
     <epg:CountriesRequest/>
  </epg:GetCountriesRequest>
 </soapenv:Body>
 </soapenv:Envelope>';
 $headers = array(
// "Accept-Encoding: gzip,deflate",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: http://epg.generic.masterdata/GetCountries",
"Content-length: ".strlen($xml_post_string),
 );
 // $url = $soapUrl;
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,            $url );
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
 curl_setopt($ch, CURLOPT_POST,           1 );
 curl_setopt($ch, CURLOPT_POSTFIELDS,     $xml_post_string );
 curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers);
 $result = curl_exec($ch);
 curl_close($ch);

echo '<pre>';
var_dump($result);
echo '</pre>';
//die();?>
<div class="CountriesResponse"></div>
<?php $clean_xml2 = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $result);
$xml2 = simplexml_load_string($clean_xml2);
var_dump($xml2);
How to&Answers: