Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't seem to get fiddler to Proxy HttpClient

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:

  1. Adding an HttpClientHandler and setting up the proxy.
  2. added the following to app.config

    <system.net>
    <defaultProxy>
      <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/>
    </defaultProxy>
    

  3. 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.

like image 794
coding4fun Avatar asked Dec 04 '25 10:12

coding4fun


1 Answers

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.

like image 66
EricLaw Avatar answered Dec 07 '25 07:12

EricLaw