我正在尝试使用凭据从客户端站点的 Windows 服务对代理服务器进行身份验证,但不断收到以下响应:StatusCode: 407, ReasonPhrase: 'Proxy Authentication Required', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: {Pragma: no-cacheProxy-Connection: closeConnection: closeCache-Control: no-cacheProxy -验证:NTLMSet-Cookie:BCSI-CS-2737f33ff5b5f739=2;路径=/内容长度:1351内容类型:文本/html;字符集=utf-8}我的本地代理配置完全不同,我无法重现该问题。这是我用来与服务器进行身份验证的代码。(如代码中所述,它基于:HttpClient 和使用代理 - 不断获得 407 private HttpClient GenerateHttpClientWithProxySettings(){ //Code based on https://stackoverflow.com/questions/29856543/httpclient-and-using-proxy-constantly-getting-407 // First create a proxy object var proxy = new WebProxy() { Address = new Uri($"{Settings.ProxyAddress}:{Settings.PortNumber}"), BypassProxyOnLocal = false, UseDefaultCredentials = false, // *** These creds are given to the proxy server, not the web server *** Credentials = new NetworkCredential( userName: Settings.ProxyUserName, password: Settings.ProxyPassword) }; //Debug: Settings.log.Debug($"{Settings.ProxyAddress}:{Settings.PortNumber}"); Settings.log.Debug(Settings.ProxyUserName); Settings.log.Debug(Settings.ProxyPassword); // Now create a client handler which uses that proxy var httpClientHandler = new HttpClientHandler() { Proxy = proxy, UseProxy = true, AllowAutoRedirect = true, };对我在这里做错的任何帮助将不胜感激。
1 回答
幕布斯7119047
TA贡献1794条经验 获得超8个赞
从响应头
Proxy-Authenticate: NTLM
代理接受 Windows 凭据而不是用户名/密码。
试试这个
var proxy = new WebProxy()
{
...
UseDefaultCredentials = true
/*Credentials = new NetworkCredential(
userName: Settings.ProxyUserName,
password: Settings.ProxyPassword)*/
};
- 1 回答
- 0 关注
- 180 浏览
添加回答
举报
0/150
提交
取消