How to monitor localhost network traffic from .NET code with Fiddler

Posted: (EET/GMT+2)

 

Telerik's Fiddler is a handy HTTP proxy for inspecting requests and responses from your .NET applications. By default, it listens on 127.0.0.1:8888 and can capture traffic as long as your app is configured to use the system proxy (or Fiddler explicitly).

In a .NET Framework app, make sure you are not bypassing the proxy for localhost. One option is to use the default proxy settings:

HttpClientHandler handler = new HttpClientHandler()
{
    UseProxy = true,
    Proxy = WebRequest.DefaultWebProxy
};

using (var client = new HttpClient(handler))
{
    var result = await client.GetAsync("http://localhost:5000/");
}

If you want to be explicit, you can point directly to Fiddler:

HttpClientHandler handler = new HttpClientHandler()
{
    Proxy = new WebProxy("http://127.0.0.1:8888"),
    UseProxy = true
};

Also, be sure to check Fiddler's own settings under Tools/Options/Connections and make sure you have the "Allow remote computers to connect" option set, if you debug traffic from other machines.

For HTTPS, Fiddler can generate and install a root certificate so it can decrypt SSL traffic. Only enable this on development machines and never in production.