
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:
http://www.telerik.com/download/fiddler/fiddler2
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(
array(
"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.
1 Response
[…] Best way to make sure that cookies are being set is to capture the HTTP requests using a tool like Fiddler. Check out this post on how to use fiddler with Guzzle: https://tricksty.com/coding/guzzle-how-to-capture-requests-responses-using-fiddler […]