I found several questions about this but they seem to resolve windows authentication. I have custom users and passwords and this code works with other existing proxies. Now since a week we use new proxy servers that use {Basic realm="Private Proxies - Password Auth"}
and the code does not work.
var user = "********";
var pass = "********";
var port = "********";
var ip = "********";
var url = "********";
var baseUrl = "********";
NetworkCredential cr = new NetworkCredential(user, pass);
cr.Domain = ip;
WebProxy proxy = new WebProxy(ip + ":" + port) { BypassProxyOnLocal = false, Credentials = cr, UseDefaultCredentials = false};
HttpClientHandler handler = new HttpClientHandler();
handler.Proxy = proxy;
handler.UseProxy = true;
HttpClient httpClient = new HttpClient(handler);
httpClient.BaseAddress = new Uri(baseUrl);
var result = httpClient.GetAsync(url).Result;
Console.WriteLine(result.Content.ReadAsStringAsync().Result);
Console.Read();
I have tested the credentials with Firefox and there the proxies work after I provide the credentials in a popup. I set the NetworkCredential inside the proxy, but when I do a request it just returns 407: Proxy Authentication Required
.
I tried to set the Proxy-Authorization
header manually. It still does not work.
Does anyone know how to fix this!?