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

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

    To expand on Bartho Bernsmann's answer, I should like to add that one can have a universal, future-proof implementation at the expense of a little reflection:

    static void AllowAllSecurityPrototols()
    {   int                  i, n;
        Array                types;
        SecurityProtocolType combined;
    
        types = Enum.GetValues( typeof( SecurityProtocolType ) ); 
        combined = ( SecurityProtocolType )types.GetValue( 0 );
    
        n = types.Length;
        for( i = 1; i < n; i += 1 )
        {   combined |= ( SecurityProtocolType )types.GetValue( i );  }
    
        ServicePointManager.SecurityProtocol = combined;
    }
    

    I invoke this method in the static constructor of the class that accesses the internet.

提交回复
热议问题