我发现了几个有关此问题,但它们似乎解决了Windows身份验证问题。我有自定义用户和密码,此代码适用于其他现有代理。现在,自从一周以来,我们使用使用{Basic realm="Private Proxies - Password Auth"}
的新代理服务器,但代码不起作用。
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();
我已经使用Firefox测试了凭据,并且在我在弹出窗口中提供凭据后代理工作。我在代理中设置了NetworkCredential,但是当我执行请求时,它只返回407: Proxy Authentication Required
。
我尝试手动设置Proxy-Authorization
标头。它仍然无效。
有谁知道如何解决这个问题??
答案 0 :(得分:0)
您需要填写Proxy-Authorization
标题:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization