Is there a way to use an HTTPS proxy in .NET 6?
Dominik Bakos
0
Reputation points
I need to check if certain HTTPS
proxies are working. If I try to access the base-address
without the proxy, it works fine. Using the proxy I get an error saying I can only use HTTP
or SOCKS
proxies. The problem is, I wasn't able to find an alternate solution that supports HTTPS
proxies. Here is my code so far:
var proxy = new WebProxy($"https://proxy-server:port");
var handler = new HttpClientHandler { Proxy = proxy };
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://base-address");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
try
{
var content = client.GetStringAsync(filepath).Result;
Console.WriteLine(content);
}
catch (Exception e)
{
Console.WriteLine("Failed. Reason: " + e);
}
}