【问题标题】:how to capture outgoing soapclient request?如何捕获传出的soapclient请求?
【发布时间】:2011-12-26 13:42:10
【问题描述】:

我已经尝试了几个可能的解决方案(例如使用 ob_),但没有任何运气。

我希望能够显示以筛选传出请求以便对其进行调试。

【问题讨论】:

    标签: php soap-client


    【解决方案1】:

    我通过扩展SoapClient 和覆盖_soapcall()_doRequest() 等方法来调试SoapClient。在我的项目中,我有一个将 XML/参数写入文件的记录器。

    我的示例包括 _soapCall()_doRequest()。我用两种方法打印出不同的东西。可能适合您的调试需求。我喜欢阅读来自 __soapCall() 的 $args 输出,并且喜欢将 XML 复制到 SoapUI 以进行验证 (Alt+V)。如果您正在调试身份验证或其他错误情况,HTTP 标头也可能很有趣。

    class MySoapClient extends SoapClient {
        public function __soapCall ($function_name, array $args, array $options = null, $input_headers = null, array &$output_headers = null) {
            // Dump $args to file, browser printout, console, etc
            var_dump($args);
    
            parent::__soapCall ($function_name, $args, $options, $input_headers, $output_headers);
    
            // XML request and response:
            var_dump($this->__getLastRequest()); // Request sent to server
            var_dump($this->__getLastResponse()); // Response from server
    
            // HTTP headers:
            var_dump($this->__getLastRequestHeaders());
            var_dump($this->__getLastResponseHeaders());
        }
    
        public function __doRequest ( string $request , string $location , string $action , int $version, int $one_way = 0 ) {
            var_dump($request); // XML
    
            $response = parent::__doRequest ($request, $location, $action, $version, $one_way);
            var_dump($response); // XML
    
            return $response;
        }
    }
    
    $webservice = new MySoapClient('http://example.com/myservice?wsdl');
    $webservice->__soapCall('SomeOperation', array($someArguments));
    

    可以使用记录器代替 var_dump:

    logger('debug', $this->__getLastRequest());
    

    【讨论】:

    • 对于我的生活,我无法弄清楚为什么我不能覆盖 __soapCall。我定义了你提供的函数,它没有被拾取。
    猜你喜欢
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多