idhttp下载html的代码(含错误处理)
IdHTTP_Thread := TIDHTTP.Create;
IdHTTP_Thread.ReadTimeout := 240000;
IdHTTP_Thread.ConnectTimeout := 240000;
IdHTTP_Thread.Request.UserAgent :='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)';
try
try
TStmHtml := TStringStream.Create('');
IdHTTP_Thread.Get(FGetURL,TStmHtml);
strHtml := TStmHtml.DataString ;
//strHtml := FParameter;
except
on E:EIdSocketError do
begin
FImpInfo := IntToStr(iLoop)+' 获得'+FGetURL+'职位信息时出现错误丢失一页 错误原因: '+SysErrorMessage(E.LastError );
FErrCode := E.LastError;
ReGetHtml := True;
end;
else
begin
FImpInfo := IntToStr(iLoop)+' 获得'+FGetURL+'职位信息时出现错误丢失一页 错误原因: 打开网页失败';
FErrCode := 1 ;
ReGetHtml := True;
end;
end;
finally
IdHTTP_Thread.Disconnect ;
IdHTTP_Thread.Free ;
TStmHtml.Free ;
end;