简体   繁体   English

如何截获PHP Soap Client的HTTP请求?

[英]How can I intercept the HTTP request of a PHP Soap Client?

I have implemented a SoapClient in PHP and I need to debug calls made to the Soap server. 我已经在PHP中实现了SoapClient,我需要调试对Soap服务器的调用。 I would like to intercept the HTTP calls when I run my PHP code in order to retrieve the body content. 我想在运行PHP代码时拦截HTTP调用以检索主体内容。

Is this possible? 这可能吗? How can I achieve this? 我该如何实现? I am under Linux. 我在Linux下。

Extend the SoapClient class and redefine the method __doRequest() . 扩展SoapClient类并重新定义方法__doRequest() This is where the HTTP request is sent to the server. 这是HTTP请求发送到服务器的位置。 If you are happy with the default implementation, all you have to do is to log the values it receives as arguments, call the parent implementation, log the value it returns and also return it. 如果您对默认实现感到满意,那么您要做的就是记录它接收到的值作为参数,调用父实现,记录它返回的值并返回它。 Use the new class instead of SoapClient whenever you need to log the communication between the SOAP client and server. 每当需要记录SOAP客户端和服务器之间的通信时,请使用新类而不是SoapClient

Something along these lines: 遵循以下原则:

class MySoapClient extends SoapClient
{
    public string __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        // Log the request here
        echo('$action='.$action."\n");
        echo('$request=[[['.$request."]]]\n");

        // Let the parent class do the job
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);

        // Log the response received from the server
        echo('$response=[[['.$response."]]]\n");

        // Return the response to be parsed
        return $response;
    }
}

Use the log method of your choice instead of echo() in the code above. 使用您选择的log方法代替上面的代码中的echo()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM