gpt4 book ai didi

c# - 基础连接已关闭。 (HttpWebRequest)

转载 作者:行者123 更新时间:2023-11-30 20:41:22 25 4
gpt4 key购买 nike

我有一个正在工作的 HttpWebRequest,几周后,它突然停止工作并开始抛出错误:

这是我的代码:

The underlying connection was closed: An unexpected error occurred on a send

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{}

我做错了什么?

最佳答案

经过长时间的研究,我找到了答案。

你需要添加ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
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();

关于c# - 基础连接已关闭。 (HttpWebRequest),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com