How can I see the actual XML generated by the PHP SOAP Client Class?

Consider this example SOAP Client script:

$SOAP = new SoapClient($WDSL); // Create a SOAP Client from a WSDL // Build an array of data to send in the request. $Data = array('Something'=>'Some String','SomeNumber'=>22); $Response = $SOAP->DoRemoteFunction($Data); // Send the request. 

In the last line, PHP takes arguments from the array you specified and, using WSDL, builds an XML request to send and sends it.

How can I get PHP to show me the actual XML that it built?

I was looking for an application and should see the actual XML request.

+45
soap xml php
Aug 26 '10 at 6:02
source share
7 answers

Use getLastRequest . It returns the XML sent in the last SOAP request.

 echo "REQUEST:\n" . $SOAP->__getLastRequest() . "\n"; 

And remember, this method only works if the SoapClient object was created with the trace option set to TRUE . Therefore, when creating an object, use this code:

 $SOAP = new SoapClient($WDSL, array('trace' => 1)); 
+78
Aug 26 '10 at 6:08
source share
 $SOAP = new SoapClient($WSDL, array('trace' => true)); $Response = $SOAP->DoRemoteFunction($Data); echo "REQUEST:\n" . htmlentities($SOAP->__getLastRequest()) . "\n"; 

this will not print the last request, but also makes the xml tags visible in the browser

+14
Oct 11 '10 at 20:12
source share

If you want to view the request without actually connecting, you can override the SoapClient __doRequest method to return XML:

 class DummySoapClient extends SoapClient { function __construct($wsdl, $options) { parent::__construct($wsdl, $options); } function __doRequest($request, $location, $action, $version, $one_way = 0) { return $request; } } $SOAP = new DummySoapClient('http://example.com/?wsdl', array('trace' => true)); echo $SOAP->GetRequestDetail($params); 
+10
Apr 07 '14 at 19:36
source share

Quinn response extension, you can also simply register a request before executing the request.

 class SoapClientDebug extends SoapClient { public function __doRequest($request, $location, $action, $version, $one_way = 0) { error_log("REQUEST:\n" .$request . "\n"); error_log("LOCATION:\n" .$location . "\n"); error_log("ACTION:\n" .$action . "\n"); error_log("VERSION:\n" .$version . "\n"); error_log("ONE WAY:\n" .$one_way . "\n"); return parent::__doRequest($request, $location, $action, $version, $one_way); } } 
+7
Aug 13 '14 at 19:05
source share

You need to enable tracing when creating SoapClient. For example:

 $SOAP = new SoapClient($WSDL, array('trace' => true)); $Data = array('Something'=>'Some String','SomeNumber'=>22); 

Then call the __getLastRequest method after you make a service call to see the XML.

 $Response = $SOAP->DoRemoteFunction($Data); echo $SOAP->__getLastRequest(); 

This will result in an XML request.

Additional information: http://www.php.net/manual/en/soapclient.getlastrequest.php

+6
Aug 26 '10 at 6:14
source share

if you use a local client, Fiddler is a great way to implement messages on Explorer. / p>

If you use it remotely, you can use something like Apache TCPMON Standalone or through eclipse *

* just links to Google’s first hit

+3
Aug 26 '10 at 6:28
source share

The problem with Quinn Comendant's answer is that $request from __doRequest() will be processed by __call() , and then the user will see an array of parameters of the real xml request. To prevent this, you can use a workaround like this:

 class DummySoapClient extends SoapClient { function __construct($wsdl, $options) { parent::__construct($wsdl, $options); } function __doRequest($request, $location, $action, $version, $one_way = 0) { throw new Exception($request); } function __call($function_name, $arguments) { try { parent::__call($function_name, $arguments); } catch (Exception $e) { return $e->getMessage(); } } } 

The trace option is not needed here because we do not call __getLastRequest() or other appropriate functions.

0
May 12 '17 at 7:34 a.m.
source share



All Articles