SoapClient::__getLastResponse

(PHP 5, PHP 7, PHP 8)

SoapClient::__getLastResponseReturns last SOAP response

说明

public SoapClient::__getLastResponse ( ) : string|null

Returns the XML received in the last SOAP response.

Note:

This method works only if the SoapClient object was created with the trace option set to true.

参数

此函数没有参数。

返回值

The last SOAP response, as an XML string.

范例

Example #1 SoapClient::__getLastResponse() example

<?php
$client 
SoapClient("some.wsdl", array('trace' => 1));
$result $client->SomeFunction();
echo 
"Response:\n" $client->__getLastResponse() . "\n";
?>

参见

User Contributed Notes

mayurvirkar at gmail dot com 09-Sep-2013 08:38
Just to make it a bit more readable

echo "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.
bshafs at gmail dot com 22-Jun-2011 12:45
You don't need to surround SoapClient in a try-catch block.  Just set the "exceptions" option to false, and the SoapFault instance will be returned instead of thrown.
ceo at l-i-e dot com 04-Jan-2006 01:31
D'oh!
That example needs:
$soapClient = new SoapClient($url, array('trace'=>1));
to turn ON tracing in the first place.
ceo at l-i-e dot com 04-Jan-2006 01:30
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
PHP8中文手册 站长在线 整理 版权归PHP文档组所有