Injecting proxy credentials to all HttpClient requests

Viewed 414

I'm working on a corporate ASP.NET Core application that needs to reach out to a cloud resource (Elastic APM).

Unfortunately, our corporate proxy is swatting down the request before it can complete. It's not my code that making the requests but code within a NuGet package, so I can't easily change how it's making the connection.

I'm hoping to use middleware to inject the proxy details before it goes out the door. I've tried this below, but it doesn't seem to be working:

services.AddHttpClient<HttpClient>().ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
    Proxy = new WebProxy(new Uri("http://proxy.mycompany.com:8080"), true, new string[]{}, CredentialCache.DefaultCredentials)
});

Long-term, I am going to whitelist the cloud resource. But as I prototype this solution, I'd prefer not to go through that red tape...

0 Answers
Related