Inspect XML created by PHP SoapClient call before/without sending the request

前端 未结 3 1402
忘掉有多难
忘掉有多难 2020-12-04 11:35

The question: Is there a way to view the XML that would be created with a PHP SoapClient function call BEFORE you actually send the request?

background:

I am

相关标签:
3条回答
  • 2020-12-04 11:53

    Upfront remark: In order to use the __getLastRequest() method successfully, you have to set the 'trace' option to true on client construction:

    $client = new SoapClient('wsdldoc.asmx?WSDL', array('trace' => TRUE));
    

    This way, your request will still be sent (and therefore still fail), but you can inspect the sent xml afterwards by calling $client->__getLastRequest().


    Main answer:

    To get access to the generated XML before/without sending the request, you'd need to subclass the SoapClient in order to override the __doRequest() method:

    class SoapClientDebug extends SoapClient
    {
      public function __doRequest($request, $location, $action, $version, $one_way = 0) {
          // Add code to inspect/dissect/debug/adjust the XML given in $request here
    
          // Uncomment the following line, if you actually want to do the request
          // return parent::__doRequest($request, $location, $action, $version, $one_way);
      }
    }
    

    You'd then use this extended class instead of the original SoapClient while debugging your problem.

    0 讨论(0)
  • 2020-12-04 11:54

    I don't believe there is a way that you'll be able to see any XML that's being created... mainly because the function is failing on it's attempt to create/pass it.

    Not sure if you tried already, but if you're having trouble trying to decide what exactly you need to pass into the function you could use:

    $client->__getTypes();

    http://us3.php.net/manual/en/soapclient.gettypes.php

    Hope this helps!

    0 讨论(0)
  • 2020-12-04 11:57

    I found this thread while working on the same problem, and was bummed because I was using classes that already extended the SoapClient() class and didn't want to screw around with it too much. However if you add the "exceptions"=>0 tag when you initiate the class, it won't throw a Fatal Error (though it will print an exception):

    SoapClient($soapURL,array("trace" => 1,"exceptions"=>0));
    

    Doing that allowed me to run __getLastRequest() and analyze the XML I was sending.

    0 讨论(0)
提交回复
热议问题