WinXP.Http.Post请求错误提示:基础连接已经关闭:发送时发生错误

1.在winXP中报错,项目用到第三方的api(post请求有header),在win7,win10没有异常,在winXP中报以下错误:

 

 (在网上查了一下,说是winXP不支持更高级别的TLS协议 https://www.codebye.com/httpwebrequest-https-tls-12-connect-close.html
2.解决方法(https://blog.csdn.net/qq_25529085/article/details/92792998):
a.把winXp伪装成Windows Embedded POSready 2009

方法:新建一个文本,写入以下内容,然后把后缀改为:reg 双击执行后 重启电脑
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\WPA\PosReady]
"Installed"=dword:00000001

b.下载补丁kb4019276 http://www.catalog.update.microsoft.com/Search.aspx?q=KB4019276 (选择product:Windows XP Embedded)
c.下载补丁KB4467770 http://www.catalog.update.microsoft.com/Search.aspx?q=KB4467770 (选择product:Windows XP Embedded)
d.安装以上两个补丁,重启电脑

3.以为这样就完事了吗?出现另外一个错误:

解决方法:在请求之前插入一行代码:
ServicePointManager.ServerCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => true;

or

private bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
{
// trust any certificate!!!
//System.Console.WriteLine("Warning, trust any certificate");
return true;
}

请求前加入以下代码

ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;


搞掂,收工~

 

 

 



posted @ 2020-05-25 19:24  Nemo君  阅读(858)  评论(0编辑  收藏  举报