如何拦截PHP Soap客户端的HTTP请求?

Jér*_*nge 1 php soap http document-body

我在PHP中实现了一个SoapClient,我需要调试对Soap服务器的调用.我想在运行PHP代码时拦截HTTP调用以检索正文内容.

这可能吗?我怎样才能做到这一点?我在Linux下.

axi*_*iac 5

扩展SoapClient类并重新定义方法__doRequest().这是HTTP请求发送到服务器的位置.如果您对默认实现感到满意,那么您所要做的就是将它接收的值记录为参数,调用父实现,记录它返回的值并返回它.使用新类而不是SoapClient在需要记录SOAP客户端和服务器之间的通信时.

这些方面的东西:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用您选择的日志方法而不是echo()上面的代码.