Search code examples
asp.net-mvcasp.net-web-apifiddler

Fiddler not capturing local traffic from webClient on LINQPad


Team,

I have the following simple WebClient call from LINQPad. How ever I try Fiddler just refuses to capture. I am just running out of ways. Instead of 127.0.0.1, I have tried localhost, localhost.(with dot), localhost.fiddler, and my machine name. Fiddler is just not interested to capture this at all. Any one has any ideas.

void Main()
{
    CookieWebClient client = new CookieWebClient() 
    {    
        Proxy = new WebProxy("127.0.0.1", 8888)    // Fiddler 
    };             
    Console.WriteLine(client.DownloadString(url)); // Cookie is created here 
    Console.WriteLine(client.DownloadString(url)); //  In this request, the cookie gets sent back to the web API
    Console.WriteLine("Done");
}

// Define other methods and classes here

public class CookieWebClient : WebClient 
{    
    private CookieContainer jar = new CookieContainer(); 
    protected override WebRequest GetWebRequest(Uri address)    
    {        
        WebRequest request = base.GetWebRequest(address);                     
        HttpWebRequest webRequest = request as HttpWebRequest;        
        if (webRequest != null)            
            webRequest.CookieContainer = jar;                     
        return request;    
    } 
}
string url = "http://localhost:21531/api/employees/12345"; 

Solution

  • You haven't explained what actually happens when you try.

    The .NET Framework bypasses the proxy for any HTTP/HTTPS request to localhost, so you must use localhost.fiddler as the host in your string url. When you do so, there are two possibilities:

    1. The request succeeds, which means that Fiddler captures the traffic
    2. The request fails, which means that your client isn't properly configured to proxy its requests.