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