2

为了抓取一个 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;
4

1 回答 1

2

尝试调用 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));
于 2013-07-24T20:52:52.517 回答