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

前端 未结 8 627
一个人的身影
一个人的身影 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:42

    My Hosting server block requesting URL And code site getting the same error Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

    After a lot of time spent and apply the following step to resolve this issue

    1. Added line before the call web URL

      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

    2. still issue not resolve then I upgrade .net version to 4.7.2 but I think it's optional

    3. Last change I have checked my hosting server security level which causes to TLS handshaking for this used "https://www.ssllabs.com/ssltest/index.html" site
      and also check to request URL security level then I find the difference is requested URL have to enable a weak level Cipher Suites you can see in the below image

    Now here are my hosting server supporting Cipher Suites

    here is called if you have control over requesting URL host server then you can sync this both server Cipher Suites. but in my case, it's not possible so I have applied the following script in Windows PowerShell on my hosting server for enabling required weak level Cipher Suites.

    Enable-TlsCipherSuite -Name "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"
    Enable-TlsCipherSuite -Name "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
    Enable-TlsCipherSuite -Name "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"
    Enable-TlsCipherSuite -Name "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"
    Enable-TlsCipherSuite -Name "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"
    Enable-TlsCipherSuite -Name "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_256_GCM_SHA384"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_128_GCM_SHA256"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_256_CBC_SHA256"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_128_CBC_SHA256"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_256_CBC_SHA"
    Enable-TlsCipherSuite -Name "TLS_RSA_WITH_AES_256_CBC_SHA"

    after applying the above script my hosting server Cipher Suites level look like

    Then my issue resolved.

    Note: server security level downgrade is not a recommended option.

提交回复
热议问题