阅读后:
Inspect XML created by PHP SoapClient call before/without sending the request
使用本文中的代码:
Can I preview the XML that PHP SOAP wants to send before sending it?
我成功地能够预览我的Soap请求的XML Body,而无需发送到我的目标网址。 非常适合调试,喜欢它!
我也试图获得标题。 在发送xml之前可以吗?
这是我到目前为止所做的工作:
<?php
class DebugSoapClient extends SoapClient {
public $sendRequest = true;
public $echoRequest = false;
public $formatXML = false;
public function __doRequest($request, $location, $action, $version, $one_way=0) {
if ( $this->echoRequest ) {
if ( !$this->formatXML ) {
$out = $request;
} else {
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadxml($request);
$doc->formatOutput = true;
$out = $doc->savexml();
}
echo $out;
}
// if I want to send the request
if ( $this->sendRequest ) {
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
else {
return '';
}
}
}
$wsdlfile = 'http://www.w3schools.com/webservices/tempconvert.asmx?WSDL';
$client = new DebugSoapClient($wsdlfile, array('trace' => 1));
$client->sendRequest = false;
$client->echoRequest = true;
$client->formatXML = true;
$parameter = array('Fahrenheit'=>'100');
$res = $client->FahrenheitToCelsius($parameter);
var_dump($res);
// echo $client->__getLastRequestHeaders(); // this isn't working as expected
?>
我已尝试添加__getLastRequestHeaders()
,但我没有得到预期的结果。