3

看完之后:

在发送请求之前/不发送请求之前检查由 PHP SoapClient 调用创建的 XML

并使用本文中的代码:

我可以在发送之前预览 PHP SOAP 想要发送的 XML 吗?

我能够成功预览我的 Soap 请求的 XML 正文,而无需发送到我的目标 URL。非常适合调试,喜欢它!

我也在尝试获取标题。在发送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(),但没有得到预期的结果。

4

0 回答 0