Search code examples
c#asp.net-mvcproxywebclientfiddler

App absolutely refuses to use proxy for localhost requests


I have Fiddler running on port 8888

Web.config:

  <system.net>
      <defaultProxy enabled="true" useDefaultCredentials="true">
          <proxy bypassonlocal="False" proxyaddress="http://localhost:8888" usesystemdefault="False" autoDetect="False" />
      </defaultProxy>
  </system.net>

App code (specifies credentials for the API controller its talking to):

            var wc = new WebClient();
            wc.Proxy = new WebProxy(new Uri($"http://localhost:8888"), false);
            wc.Credentials = new NetworkCredential("myuser", "mypass");
            var response = wc.UploadString("http://localhost:11026/api/mycontroller/mymethod", "POST", request);

I cannot for the life of me get it to communicate via Fiddler so I can debug requests. Am I doing something wrong?

UPDATE
This information is supplied by Fiddler help but having used localhost.fiddler in both web.config and app code, still not being captured by Fiddler (and when Fiddler is closed it doesn't cause a connection failed error)

Solution 2: Use http://ipv4.fiddler

Use http://ipv4.fiddler to hit localhost on the IPv4 adapter. This works especially well with the Visual Studio test webserver (codename: Cassini) because the test server only listens on the IPv4 loopback adapter. Use http://ipv6.fiddler to hit localhost on the IPv6 adapter, or use http://localhost.fiddler to hit localhost using "localhost" in the Host header. This last option should work best with IIS Express.


Solution

  • Rather than trying to send it via the proxy, send it via one of the fiddler loopbacks.

    Such as http://fiddler.ipv4:11026 ... ...

    Details are given here:

    http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost

    Shows how to set it up and capture traffic. It is the method I've used when I want to see traffic being passed between local web apis and my Mvc project