不懂所以称之为坑
报错:
基础连接已经关闭:发送时发生错误。
由于远程方关闭传输流,身份验证失败。
然后试了加密方式
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
然后发现.net 4.0中
SecurityProtocolType只有两个值:Ssl3,Tls
新建一个.net 4.6.1的程序,找到了这个
namespace System.Net
{
//
// 摘要:
// 指定 Schannel 安全包支持的安全协议。
[Flags]
public enum SecurityProtocolType
{
//
// 摘要:
// 指定安全套接字层 (SSL) 3.0 安全协议。
Ssl3 = 48,
//
// 摘要:
// 指定传输层安全 (TLS) 1.0 安全协议。
Tls = 192,
//
// 摘要:
// 指定传输层安全 (TLS) 1.1 安全协议。
Tls11 = 768,
//
// 摘要:
// 指定传输层安全 (TLS) 1.2 安全协议。
Tls12 = 3072
}
}
枚举实际是数值,只是有个类型验证,所以
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
可行
网友评论