HttpWebRequests Failing on Subsequent Calls

前端 未结 2 1761
一个人的身影
一个人的身影 2021-01-03 03:25

I know this is a vague question, especially since I am not providing any code, but I am developing a .Net 2.0 application, and we have a WebRequest which posts data to an in

2条回答
  •  青春惊慌失措
    2021-01-03 04:18

    This usually happens if you're not disposing the WebResponse. There's a limit applied to the number of connections from a client to the same machine, and by default it's two. The connections can be reused (or closed) if you close the WebResponse. The using statement is your friend here:

    WebRequest request = [...];
    // Do stuff with the request stream here (and dispose it)
    using (WebResponse response = request.GetResponse())
    {
        // Stuff with the response
    }
    

提交回复
热议问题