如何拦截 PHP Soap 客户端的 HTTP 请求?
How can I intercept the HTTP request of a PHP Soap Client?
我在 PHP 中实现了一个 SoapClient,我需要调试对 Soap 服务器的调用。当我 运行 我的 PHP 代码以检索正文内容时,我想拦截 HTTP 调用。
这可能吗?我怎样才能做到这一点?我在 Linux.
延长SoapClient
class and redefine the method __doRequest()
。这是将 HTTP 请求发送到服务器的地方。如果您对默认实现感到满意,您所要做的就是记录它作为参数接收的值,调用父实现,记录它 returns 和 return 的值。每当您需要记录 SOAP 客户端和服务器之间的通信时,请使用新的 class 而不是 SoapClient
。
大致如下:
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;
}
}
在上面的代码中使用您选择的日志方法代替 echo()
。
我在 PHP 中实现了一个 SoapClient,我需要调试对 Soap 服务器的调用。当我 运行 我的 PHP 代码以检索正文内容时,我想拦截 HTTP 调用。
这可能吗?我怎样才能做到这一点?我在 Linux.
延长SoapClient
class and redefine the method __doRequest()
。这是将 HTTP 请求发送到服务器的地方。如果您对默认实现感到满意,您所要做的就是记录它作为参数接收的值,调用父实现,记录它 returns 和 return 的值。每当您需要记录 SOAP 客户端和服务器之间的通信时,请使用新的 class 而不是 SoapClient
。
大致如下:
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;
}
}
在上面的代码中使用您选择的日志方法代替 echo()
。