PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

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

 July 18, 2022     document-body, http, php, soap     No comments   

Issue

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.

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


Solution

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.

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.



Answered By - axiac
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing