After reading:
Inspect XML created by PHP SoapClient call before/without sending the request
And using the Code from this Article:
Can I preview the XML that PHP SOAP wants to send before sending it?
I'm successfully able to preview the XML Body of my Soap request, without sending to my target URL. Great for debugging, love it!
I'm trying to also get the Headers too. Is that possible before sending the xml?
Here's what I've got working so far:
<?php
class DebugSoapClient extends SoapClient {
public $sendRequest = true;
public $echoRequest = false;
public $formatXML = false;
public function __doRequest($request, $location, $action, $version, $one_way=0) {
if ( $this->echoRequest ) {
if ( !$this->formatXML ) {
$out = $request;
} else {
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadxml($request);
$doc->formatOutput = true;
$out = $doc->savexml();
}
echo $out;
}
// if I want to send the request
if ( $this->sendRequest ) {
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
else {
return '';
}
}
}
$wsdlfile = 'http://www.w3schools.com/webservices/tempconvert.asmx?WSDL';
$client = new DebugSoapClient($wsdlfile, array('trace' => 1));
$client->sendRequest = false;
$client->echoRequest = true;
$client->formatXML = true;
$parameter = array('Fahrenheit'=>'100');
$res = $client->FahrenheitToCelsius($parameter);
var_dump($res);
// echo $client->__getLastRequestHeaders(); // this isn't working as expected
?>
I've tried adding __getLastRequestHeaders()
and I don't get the expected result.