【问题标题】:WebRequest.Create - The operation has timed outWebRequest.Create - 操作已超时
【发布时间】:2011-08-27 01:11:08
【问题描述】:

我正在尝试在我自己的网站上抓取几个页面,但在我的实时环境中出现超时 webException("The operation has timed out") 但没有在我的测试环境中。超时不会在同一页面上发生两次,而是在一些请求之后随机且经常发生。第一次超时后,超时频率会上升。

测试环境中的 requestUristring: http://localhost/Opgaver/Flytning/Haarde-hvidevarer/Bortkoersel-amerikaner-koeleskab-paa.aspx

live 环境中的 requestUristring: http://www.servicebyen.dk/Opgaver/Flytning/Haarde-hvidevarer/Bortkoersel-amerikaner-koeleskab-paa.aspx

var webRequest = (HttpWebRequest)WebRequest.Create(requestUriString);
webRequest.KeepAlive = false;
webRequest.Timeout = 3 * 30 * 1000;
webRequest.PreAuthenticate = false;

using (WebResponse webResponse = webRequest.GetResponse()) //ERROR OCCURS HERE
{

    using (Stream responseStream = webResponse.GetResponseStream())
    {
         if (responseStream != null)
         {
              using (var reader = new StreamReader(responseStream))
              {
                   string readToEnd = reader.ReadToEnd();
                   .....          
              }

         }                
     }
 }

【问题讨论】:

  • 你的爬取代码到底在哪里?它在网络应用程序中还是在外部应用程序中?
  • 如果您在浏览器中导航到 requestUriString,您是否也会遇到超时?
  • 我的代码位于 Web 应用程序中。
  • 当我在浏览器中导航到 requestUrlString 时,页面会显示出来。
  • 你有没有得到这个答案?我有同样的问题。

标签: asp.net httpwebrequest timeout web-crawler


【解决方案1】:

我会尝试设置webRequest.ServicePoint.ConnectionLimit = 100

【讨论】:

    【解决方案2】:

    试试这个(但仅限于您的测试环境)。

    Keep-alive:如果对 Internet 资源的请求应包含一个值为

    的 Connection HTTP 标头,则为 true

    webRequest.KeepAlive = true;
    webRequest.Timeout = 95 * 95 * 100000;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多