我正在尝试使用凭据从客户端站点的 Windows 服务对代理服务器进行身份验证,但不断收到以下响应:
StatusCode: 407, ReasonPhrase: 'Proxy Authentication Required', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: {
Pragma: no-cache
Proxy-Connection: close
Connection: close
Cache-Control: no-cache
Proxy -验证:NTLM
Set-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,
};
对我在这里做错的任何帮助将不胜感激。
幕布斯7119047
相关分类