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


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/">
 $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);

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