[英]How can I intercept the HTTP request of a PHP Soap Client?
我已經在PHP中實現了SoapClient,我需要調試對Soap服務器的調用。 我想在運行PHP代碼時攔截HTTP調用以檢索主體內容。
這可能嗎? 我該如何實現? 我在Linux下。
擴展SoapClient
類並重新定義方法__doRequest()
。 這是HTTP請求發送到服務器的位置。 如果您對默認實現感到滿意,那么您要做的就是記錄它接收到的值作為參數,調用父實現,記錄它返回的值並返回它。 每當需要記錄SOAP客戶端和服務器之間的通信時,請使用新類而不是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;
}
}
使用您選擇的log方法代替上面的代碼中的echo()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.