WebRequest.GetResponse locks up?

前端 未结 1 629
南旧
南旧 2020-12-05 15:58

When writing the below my code locks up on GetResponse. Why?

        try
        {
            WebRequest myWebRequest = WebRequest.Create(strURL);
                  


        
1条回答
  •  死守一世寂寞
    2020-12-05 16:55

    This usually happens if you've made several requests to the same host, and not disposed of the WebResponse.

    The default connection management settings only allow 2 (or maybe 4, I can't remember) open connections to the same host at a time. If you really need to change this, use the app.config element - but usually you'll be fine just disposing of WebResponse:

    try
    {
        WebRequest myWebRequest = WebRequest.Create(strURL);
        using (WebResponse myWebResponse = myWebRequest.GetResponse())
        {
            //more code here
    

    0 讨论(0)
提交回复
热议问题