HttpWebRequests Failing on Subsequent Calls

给你一囗甜甜゛ 提交于 2019-11-30 15:20:08
Jon Skeet

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
}

Yep, your exactly right. The response wasn't being disposed properly. We'd been leaving this upto the garbage collector, which, you guessed it, wasnt being collected in time. Unfortunately, I closed my browser and forgot to read any answers (lol how stupid do you think I feel) and the problem is solved.

I've learned 2 things tonight. 1, dispose of your WebRequests properly; and 2, PAY MORE ATTENTION TO STACK-OVERFLOW ANSWERS!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!