C# web references 调用出错 The underlying connection was closed: An unexpected error occurred on a send.

在调用web references的位置加上try  catch 后捕捉到 error  message : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

解决办法:

在调用web references 方法前加上下面这句代码

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

导致问题的原因: 服务端提供的API的安全传输协议为TLS1.2

你可能感兴趣的:(C#)