PHPのお勉強!

PHP TOP

SoapClient::__getLastResponse

(PHP 5, PHP 7, PHP 8)

SoapClient::__getLastResponse直近の SOAP レスポンスを返す

説明

public SoapClient::__getLastResponse(): ?string

直近の SOAP レスポンスで受信した XML を返します。

注意:

このメソッドは、オプション trace を指定して SoapClient が作成されている場合のみ使用可能です。

パラメータ

この関数にはパラメータはありません。

戻り値

直近の SOAP レスポンスを XML 文字列で返します。

例1 SoapClient::__getLastResponse() の例

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

参考

add a note

User Contributed Notes 3 notes

up
12
ceo at l-i-e dot com
18 years ago
D'oh!
That example needs:
$soapClient = new SoapClient($url, array('trace'=>1));
to turn ON tracing in the first place.
up
9
ceo at l-i-e dot com
18 years ago
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
up
0
mayurvirkar at gmail dot com
11 years ago
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.
To Top