Coding, PHP

Guzzle: How to capture requests responses using Fiddler

Fiddler is a wonderful free web debugging proxy tool from Telerik.
It helps you debug web applications by capturing network traffic.

You can get it here:

When using Web HTTP Clients like Guzzle, we need to make sure that the HTTP requests sent and responses received are proper. Fiddler by default won’t capture the PHP application HTTP packets. So, we need to configure it as a proxy in our Guzzle client like this:

$client = new GuzzleHttp\Client(
"defaults" => array(
"allow_redirects" => true, "exceptions" => true,
"decode_content" => true,
'cookies' => true,
'verify' => false,
// For testing with Fiddler
'proxy' => "localhost:8899",

Make sure to set the port in localhost:[port] to the correct number. You can see it in Fiddler: Tools -> Fiddler Options -> Connections (tab) -> Fiddler listens on port.
If you are already using another proxy to make your requests, then you can set it in: Tools -> Fiddler Options -> Gateway (tab) -> Manual Proxy Configuration

This way, your request will first go to Fiddler where you can see it by double clicking the request captured. Fiddler will then send it to the proxy you specified. You can also modify requests and responses in Fiddler itself to test it out. This is very useful for Web Scraping when you need to send very specific request headers and cookies to get the correct response.

One thought on “Guzzle: How to capture requests responses using Fiddler

Leave a Reply

Your email address will not be published. Required fields are marked *