Can't seem to work with Proxy HttpClient

I am having trouble with fiddler pretend to pick up asp.net 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

    <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 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("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 like to just open the script to run the application and grab traffic (even in production) without changing the source code.

+3


source to share


1 answer


Unfortunately the .NET Framework is hardcoded to bypass proxies 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 work around this, change the request url from http://localhost:8085

to http://localhost.fiddler:8085

and Fiddler will pick up the request.

+4


source







All Articles