我有HttpWebRequest
正在运行,几周之后,它突然停止工作并开始抛出错误:
这是我的代码:
基础连接已关闭:发生意外错误 发送
HttpWebRequest FirstRequest = null;
HttpWebRequest postRequest = null;
HttpWebResponse response = null;
try
{
FirstRequest = (HttpWebRequest)WebRequest.Create("https://my.emerchantpay.com");
FirstRequest.CookieContainer = new CookieContainer();
FirstRequest.CookieContainer = _cookies;
FirstRequest.Accept = @"text/html, application/xhtml+xml, */*";
FirstRequest.Referer = @"https://my.emerchantpay.com";
FirstRequest.Headers.Add("Accept-Language", "en-GB");
FirstRequest.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
FirstRequest.Host = @"my.emerchantpay.com";
response = (HttpWebResponse)FirstRequest.GetResponse();//here is error
}catch{}
我做错了什么?
答案 0 :(得分:0)
添加后
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
和
FirstRequest.Keepalive = false;
为我工作