Proxying outbound traffic through fiddler in C#


If you want to proxy your traffic through Fiddler locally with C#, you’ll need to setup fiddler ( I use Fiddler Classic) and use a proxy in your http clients.

In Fiddler, make sure you have the following:

  • Enable it to act as a proxy ( Tools - Settings - Connections)

In your code, write a WebProxy to Fiddler and use it as a Handler in your HttpClient.


        var proxy = new WebProxy
		{
			Address = new Uri($"http://127.0.0.1:8888"), // or the IP address of the Fiddler Everywhere host machine. In case you are using a remote host, ensure that "Allow remote computers to connect" is enabled in FIddler's settings
			BypassProxyOnLocal = false,
			UseDefaultCredentials = false,
		};

		// Create a client handler that uses the proxy
		var httpClientHandler = new HttpClientHandler
		{
			Proxy = proxy,
		};

		// Disable SSL verification
		httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

		// Finally, create the HTTP client object
		using (var client = new HttpClient(handler: httpClientHandler, disposeHandler: true))
		{
            // The request you want to do
        }

This will route your requests through Fiddler, so you can inspect everything that happens.

See also

g