我用TIdHTTP控件抓取网页的源代码,我想在抓取网页的时候:如果网页不存在,那么给提示1,如果抓取网页的时候超过一个指点的时间(800毫秒)则自动断开连接,给提示2。
请问用TIdHTTP控件能实现吗?

解决方案 »

  1.   

    可以的,
     try
      http:= TIdHTTP.Create(nil);
      http.ConnectTimeout := 32000; // 32 seconds
      http.ReadTimeout := 32000; // 32 seconds
    except
      on d: EIdException do
      begin
        .....
      end;
    end;
      

  2.   

    try
      http:= TIdHTTP.Create(nil);
      http.ConnectTimeout := 32000; // 32 seconds
      http.ReadTimeout := 32000; // 32 seconds
      http.Get(url,stream);
    except
    on d: EIdException do
      begin
      .....
      end;
    end;
      

  3.   

    超过一个指点的时间(800毫秒)则自动断开连接 :用上面的方法即可
    如果网页不存在 :有一个ResponseCode,404是没找到