D'oh!That example needs:$soapClient = new SoapClient($url, array('trace'=>1));to turn ON tracing in the first place.
(PHP 5, PHP 7, PHP 8)
SoapClient::__getLastResponse — Возвращает последний SOAP-ответ
Возвращает XML, полученный в последнем SOAP-ответе.
Замечание:
Метод работает только для объекта SoapClient, созданного с настройкой
trace
, равнойtrue
.
У этой функции нет параметров.
Последний SOAP-ответ в виде строки с XML.
Пример #1 Пример использования SoapClient::__getLastResponse()
<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "Ответ:\n" . $client->__getLastResponse() . "\n";
?>
D'oh!That example needs:$soapClient = new SoapClient($url, array('trace'=>1));to turn ON tracing in the first place.
You almost for sure will need to wrap a try/catch block around your SOAP call in order to use these to debug something that's not working.Otherwise, PHP throws a fatal error before you can execute this function.For example:<?php $soapClient = new SoapClient($url); echo htmlentities($soapClient->__getFunctions()); //Assume that has output 'someFunction' (among others) try { $results = $soapClient->someFunction(...); } catch (SoapFault $soapFault) { var_dump($soapFault); echo "Request :<br>", htmlentities($soapClient->__getLastRequest()), "<br>"; echo "Response :<br>", htmlentities($soapClient->__getLastResponse()), "<br>"; }?>Without try/catch, your just get the Fatal Error and PHP commits suicide before you can call __getLastRequest/__getLastResponse
Just to make it a bit more readableecho "REQUEST:\n" . htmlentities(str_ireplace('><', ">\n<", $client->__getLastRequest())) . "\n";echo "RESPONSE:\n" . htmlentities(str_ireplace('><', ">\n<", $client->__getLastResponse())) . "\n";PS: If you are using \n then you need to enclose above statements in <pre>. You can also use <br />, but it gets a bit messy.