我使用IDHTTP获取网页失败 !1.一个是400错误,但网站却能正常访问,如网站:http://www.pk070.com/
2.一个是Socket Error # 11001 Host not found 错误,如网站:http://www1.ok1889.com/我的源码: Html:=TStringList.Create;
Params:=TStringStream.Create('');
IdHTTP:= Tidhttp.Create(nil);
try
IdHTTP.HandleRedirects:=True; //必须支持重定向否则可能出错(301错误)
IdHTTP.ReadTimeout:= 30000; //超过这个时间则不再访问
IdHTTP.Request.Accept :='image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*';
IdHTTP.Request.AcceptLanguage :='zh-cn';
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)';
IdHTTP.Get(AURL,Params);
Params.Position :=0;
Html.LoadFromStream(Params);
except
Result :='';
Exit; //如果网站不能访问就直接退出
end;
求指教!
2.一个是Socket Error # 11001 Host not found 错误,如网站:http://www1.ok1889.com/我的源码: Html:=TStringList.Create;
Params:=TStringStream.Create('');
IdHTTP:= Tidhttp.Create(nil);
try
IdHTTP.HandleRedirects:=True; //必须支持重定向否则可能出错(301错误)
IdHTTP.ReadTimeout:= 30000; //超过这个时间则不再访问
IdHTTP.Request.Accept :='image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*';
IdHTTP.Request.AcceptLanguage :='zh-cn';
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)';
IdHTTP.Get(AURL,Params);
Params.Position :=0;
Html.LoadFromStream(Params);
except
Result :='';
Exit; //如果网站不能访问就直接退出
end;
求指教!
htmlStr: string;
begin
htmlStr := idhttp1.get(http://www.pk070.com');
end;
=======================================uses IdHTTP;
function GetWebPageHTML(URL: string): string;
var
IDHTTP: TIDHttp;
begin
Result:= '';
IDHTTP:= TIDHTTP.Create(nil);
try
try
idhttp.HandleRedirects:= true; //必须支持重定向否则可能出错
idhttp.ReadTimeout:= 20000; //超过这个时间则不再访问
Result:= IDHTTP.Get(URL);//取得网页内容
except
end;
finally
IDHTTP.Free;
end;
end;