我有一个相当简单的代码,直到最近才起作用,直到将数据发送到的站点未切换到https。 在调试模式下(在本地主机上),我使用通过域登录名和密码进行访问的代理。在发布模式下,我使用了另一个不需要凭据的代理。 我尝试添加
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
它没有用!只有一半。如果凭据是按调试模式发送的,则发送请求,但会失败,但“基础连接已关闭:如果您使用DefaultCredentials,则除外。您能给我什么建议?
#if DEBUG //OK
NetworkCredential proxyCreds = new NetworkCredential(
"login",
"password"
);
WebProxy proxy = new WebProxy("http://bproxy.com:3131", false)
{
UseDefaultCredentials = false,
Credentials = proxyCreds,
};
HttpClient client = null;
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Proxy = proxy,
PreAuthenticate = true,
UseDefaultCredentials = false,
};
client = new HttpClient(httpClientHandler);
#else // NOT OK
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Proxy = new WebProxy(new Uri("http://bproxy.com:3128"))
};
HttpClient client = new HttpClient(httpClientHandler);
#endif
client.BaseAddress = new Uri("http://url.com");
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls;
var values = new Dictionary<string, string>
{
{"_method", "POST" },
{ "data[User][email]", user },
{ "data[User][password]", pass }
};
var content = new FormUrlEncodedContent(values);
var responseString = Post(client, "/", content);
答案 0 :(得分:0)
我认为您需要将托管它的网络上使用的那些代理地址列入白名单。将IP或代理地址(包括端口)列入白名单
与您的网络团队沟通。