Using 'Charles Proxy' To Debug PHP SOAP
Join the DZone community and get the full member experience.
Join For FreeI used this trick to solve a particularly sticky problem last week, so I thought I'd share. I had a 3rd party SOAP service (except it was actually a .NET WCF service, which is almost SOAP but not quite) which didn't behave in accordance with the way its documentation said it would. PHP's SoapClient
has the ability to enable tracing and give information about the request/response headers/body, which is useful, but I needed to store the outputs and also rewrite a particular request header during the course of debugging this. Enter: Charles Proxy.
I wrote about Charles at length on TechPortal recently, so if you're new to Charles that would be a good place to learn more. I set up Charles to proxy requests on port 8888, and I was running the PHP scripts on the same machine. To set the proxy, I simply added some entries to the $options
array that gets passed to the SoapClient
constructor:
$options = array( "cache_wsdl" => WSDL_CACHE_NONE, "soap_version" => SOAP_1_1, "trace" => 1, "proxy_host" => "localhost", "proxy_port" => 8888, ); $client = new SoapClient($wsdl, $options);
The specific bits that are relevant to proxying through Charles here are the proxy_host
and proxy_port
settings, this sends these SOAP requests through port 8888 on my local
machine, which is where Charles is listening for proxy activity. This
means that I can easily keep one eye on the detail of the request
without having large headers or SOAP responses all over my output or in
the logs. As I mentioned earlier, there was also a moment where we
thought that PHP was sending some incorrect headers (it wasn't) and I
was able to use Charles to rewrite just those headers, which helped us
to see that this wasn't the problem. You can also set a stream_context
option to set any specific HTTP-related settings you need to, but some headers such as Content-Type
will be ignored as the SOAP extension has clear ideas on which to send.
I hope that helps someone working with a remote SOAP service, they
aren't always easy to debug but this is one of many tools in my box so I
thought I'd share.
Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
-
What ChatGPT Needs Is Context
-
Security Challenges for Microservice Applications in Multi-Cloud Environments
-
How To Check IP Addresses for Known Threats and Tor Exit Node Servers in Java
Comments