I've been having issues getting fiddler to pick up the traffic of a self-hosted asp.net web api. My situation might be a little different in that the same application that is hosting the web api is also consuming it (yes we have reasons to do this :) ). We are using HttpClient. Here are the things I've tried:
added the following to app.config
<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/>
</defaultProxy>
Tried to hit the api from a separate .net client client (thinking the same process consuming the api that is hosting it was not allowing the traffic to be captured since it was all Intra-process).
Now if i open a web browser or postman locally and hit the api then traffic will be captured correctly
Here is the client code:
var handler = new HttpClientHandler();
handler.UseProxy = true;
handler.Proxy = new WebProxy("http://127.0.0.1",8888);
var client = new HttpClient(handler) {BaseAddress = new Uri(new Uri("http://localhost:8085"), "api/companies")};
HttpResponseMessage response;
using (client)
{
response = client.GetAsync(client.BaseAddress).Result;
}
var result = response.Content.ReadAsAsync<IEnumerable<Company>>().Result;
Now ideally i would want just to be able to open fiddler on a running app and capture traffic (even in production) without having to change the source code.
Unfortunately, the .NET Framework is hardcoded to bypass the proxy for Localhost addresses (see my feature request here: https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6359204-support-the-loopback-token-in-proxy-bypass-lists)
To workaround this, change your request URL from http://localhost:8085 to http://localhost.fiddler:8085 and Fiddler will pick up the request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With