PHP 5.4.33 Released

SoapClient::__getLastResponse

(PHP 5 >= 5.0.1)

SoapClient::__getLastResponseGibt die letzte SOAP-Antwort zurück

Beschreibung

public string SoapClient::__getLastResponse ( void )

Gibt das XML zurück, das mit der letzten SOAP-Antwort gesendet wurde.

Hinweis:

Diese Methode funktioniert nur, wenn das SoapClient-Objekt mit trace=TRUE erstellt wurde.

Parameter-Liste

Diese Funktion hat keine Parameter.

Rückgabewerte

Die letzte SOAP-Antwort als XML-Zeichenkette.

Beispiele

Beispiel #1 SoapClient->__getLastResponse()-Beispiel

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

Siehe auch

add a note add a note

User Contributed Notes 4 notes

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