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

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

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

    This problem occurs when the server or another network device unexpectedly closes an existing Transmission Control Protocol (TCP) connection. This problem may occur when a time-out value on the server or on the network device is set too low. To resolve this problem, see resolutions A, D, E, F, and O. The problem can also occur if the server resets the connection unexpectedly, such as if an unhandled exception crashes the server process. Analyze the server logs to see if this may be the issue.

    Resolution

    To resolve this problem, make sure that you are using the most recent version of the .NET Framework.

    Add a method to the class to override the GetWebRequest method. This change lets you access the HttpWebRequest object. If you are using Microsoft Visual C#, the new method must be similar to the following.

    class MyTestService:TestService.TestService
    {
        protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
            //Setting KeepAlive to false
            webRequest.KeepAlive = false;
            return webRequest;
        }
    }
    

    Excerpt from KB915599: You receive one or more error messages when you try to make an HTTP request in an application that is built on the .NET Framework 1.1 Service Pack 1.

提交回复
热议问题