开发者

Get SOAP XML before __soapCall? [duplicate]

开发者 https://www.devze.com 2022-12-15 21:30 出处:网络
This question already has answers here: Inspect XML created by PHP SoapClient call before/without sending the request
This question already has answers here: Inspect XML created by PHP SoapClient call before/without sending the request (3 answers) Closed last year.

Is it possible to get the XML generated by SOAP Client before sending it to webservice?

I need this because response from webservice if one of parameters is really wrong I get errors like

Server was unable to read request. 
---> There is an error in XML document (2, 408). 
---> Input string was not 开发者_如何学Cin a correct format.

This typically includes firing up tcpmon or some other tcp watcher utility, capturing the webservice call, copy and paste xml to text editor and go to column 408 to see what's the problem.

I'd really like to simplify this process by getting the XML before sending it.


It is very, very hard (nigh impossible) to do that. What is much easier is using the SoapClient class' built-in debugging functionality to output the request after it has been sent. You can do that like so:

First, when creating your SOAPClient, enable tracing, like so:

$client = new SoapClient($wsdl, array('trace' => true));

Then do whatever processing is necessary to get ready to make the SOAP call and make it. Once it has been made, the following will give you the request you have just sent:

echo("<pre>"); //to format it legibly on your screen
var_dump($client->__getLastRequestHeaders()); //the headers of your last request
var_dump($client->__getLastRequest()); //your last request

And, if you want to see the response as well, the following should work:

var_dump($client->__getLastResponseHeaders()); //response headers
var_dump($client->__getLastResponse()); //the response
0

精彩评论

暂无评论...
验证码 换一张
取 消