InternetReadFile超时?

时间:2013-07-24 20:26:02

标签: delphi

要抓取一个html页面我已经使用了以下一段时间没有问题。我现在每当网站需要很长时间(1分钟)来提供服务时,我才会收到I / O 1784错误。我猜测真正的错误是我的进程超时了。我该如何延长时间?

function GetInternetFile(const fileURL, FileName: string): boolean;
const
  BufferSize = 1024;
  var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: file;
  sAppName: string;
begin
  sAppName := ExtractFileName(Application.ExeName);
  hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil,
    nil, 0);
  try
    Screen.Cursor := crHourGlass;
    hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0);
    try
      AssignFile(f, FileName);
      Rewrite(f, 1);
      i := 0;
      repeat
        InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
        BlockWrite(f, Buffer, BufferLen);
      until BufferLen = 0;
      CloseFile(f);
      result := True;
    finally
      InternetCloseHandle(hURL)
    end
  finally
    InternetCloseHandle(hSession);
    Screen.Cursor := crDefault;
  end
end;

1 个答案:

答案 0 :(得分:1)

尝试调用InternetSetOption();以下是我们在冗长的SOAP调用之前设置发送和接收超时的方法:

var
  TimeOut: Integer;
begin
  TimeOut := (NumSecs * 1000);
  InternetSetOption(Data, INTERNET_OPTION_RECEIVE_TIMEOUT,  
                    Pointer(@TimeOut),       SizeOf(TimeOut));
  InternetSetOption(Data, INTERNET_OPTION_SEND_TIMEOUT,  Pointer(@TimeOut),  
                    SizeOf(TimeOut));