如何截获PHP Soap Client的HTTP请求? [英] How can I intercept the HTTP request of a PHP Soap Client?

查看:105
本文介绍了如何截获PHP Soap Client的HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have implemented a SoapClient in PHP and I need to debug calls made to the Soap server. I would like to intercept the HTTP calls when I run my PHP code in order to retrieve the body content.

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

Is this possible? How can I achieve this? I am under Linux.

推荐答案

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

Extend the SoapClient class and redefine the method __doRequest(). This is where the HTTP request is sent to the server. 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.

遵循以下原则:

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;
    }
}

使用您选择的log方法代替上面的代码中的echo().

Use the log method of your choice instead of echo() in the code above.

这篇关于如何截获PHP Soap Client的HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆