最佳答案
密码如下:
HttpClient client = null;
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Proxy = new WebProxy(string.Format("{0}:{1}", proxyServerSettings.Address,
proxyServerSettings.Port),false),
PreAuthenticate = true,
UseDefaultCredentials = false,
};
this.httpClientHandler.Credentials = new NetworkCredential(proxyServerSettings.UserName,
proxyServerSettings.Password);
this.client = new HttpClient(this.httpClientHandler);
当我最终做到这一点:
HttpResponseMessage httpResponseMessage = this.client.PostAsync(urlToPost, new StringContent(data, Encoding.UTF8, this.mediaType)).Result;
它总是抛出
远程服务器返回一个错误: (407)代理身份验证 需要。
我完全不明白。
当在 IE10中配置时,或者如果我使用 HttpWebRequest
类,同样的代理设置可以正常工作