idhttp读取网页,代码完整,Xe2有错
procedure InitHttp(var Id_HTTP: TIdHTTP);
begin
Id_HTTP.ConnectTimeout:= 10000;
Id_HTTP.ReadTimeout := 10000;
Id_HTTP.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*';
Id_HTTP.Request.AcceptLanguage := 'zh-cn';
Id_HTTP.Request.ContentType := 'application/x-www-form-urlencoded';
Id_HTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)';
Id_HTTP.HandleRedirects:=true;//防止网页跳转出现的错误(idhttp http/1.1 302 object moved)
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ss : TStringStream;
url:string;
Idhttp1:TIdhttp;
begin
url:='http://www.pep.com.cn/czyw/jszx/tbjxzy/jsys/bs/201008/t20100825_727200.htm';
ss :=TStringStream.Create('');
IdHTTP1 := TIdHTTP.Create(nil);
try
try
InitHttp(IdHTTP1);
Idhttp1.Get(URL,ss);
showmessage(ss.DataString);
except
end;
finally
IdHTTP1.Free;
ss.Free;
end;
end;