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

前端 未结 8 632
一个人的身影
一个人的身影 2020-11-28 06:49

I have the following code:

private Uri currentUri;

private void Form1_Load(object sender, EventArgs e)
{
    currentUri = new Uri(@\"http://www.stackoverflo         


        
8条回答
  •  醉酒成梦
    2020-11-28 07:46

    • .NET 4.6 and above. You don’t need to do any additional work to support TLS 1.2, it’s supported by default.
    • .NET 4.5. TLS 1.2 is supported, but it’s not a default protocol. You need to opt-in to use it. The following code will make TLS 1.2 default, make sure to execute it before making a connection to secured resource:
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

    • .NET 4.0. TLS 1.2 is not supported, but if you have .NET 4.5 (or above) installed on the system then you still can opt in for TLS 1.2 even if your application framework doesn’t support it. The only problem is that SecurityProtocolType in .NET 4.0 doesn’t have an entry for TLS1.2, so we’d have to use a numerical representation of this enum value:
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

    • .NET 3.5 or below. TLS 1.2 is not supported. Upgrade your application to more recent version of the framework.

提交回复
热议问题