January 7, 2014

Proxying HttpClient requests through Fiddler

To proxy external requests set the Proxy property of HttpClientHandler:

    private static HttpClient client 
        = new HttpClient(new HttpClientHandler()
        {
            Proxy = new WebProxy("localhost", 8888)
        });

This will not work for localhost requests since these bypass proxies by default. Instead you can suffix the request URL with .fiddler. This is why it is a good idea to store your API endpoints in app/web.config:

<add key="ApiEndpoint" value="http://localhost.fiddler:49978" />

© 2022 Ben Foster