Can't seem to work with Proxy HttpClient

I am having trouble with fiddler pretend to pick up web api self service traffic. My situation may be slightly different from the fact that the same application that hosts the web api also consumes it (yes, we have reasons to do that :)). We are using HttpClient. Here's what I've tried:

  • Adding the HttpClientHandler and configuring the proxy.
  • added the following to app.config

      <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/>

  • Tried to hit the api from a separate .net client client (thinking that the same process that uses the api that hosts it does not allow traffic to be captured as it was the whole Intra process).

Now if I open a web browser or postman locally and hit the api then the traffic is captured correctly.

Here is the client code:

    var handler = new HttpClientHandler();
    handler.UseProxy = true;
    handler.Proxy = new WebProxy("",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 like to just open the script to run the application and grab traffic (even in production) without changing the source code.


source to share

1 answer

Unfortunately the .NET Framework is hardcoded to bypass proxies for Localhost addresses (see my feature request here: token-in-proxy-bypass-lists )

To work around this, change the request url from http://localhost:8085

to http://localhost.fiddler:8085

and Fiddler will pick up the request.



All Articles