function TForm1.IdHTTPGet(aURL: string; var sWeb: string): Boolean;
var
IdHTTP: TIdHTTP;
SS_Response: TStringStream; // 提交后返回的数据
begin
Result := False;
if aURL = '' then Exit;
sWeb := '';
IdHTTP := TIdHTTP.Create(nil);
try
try
with IdHTTP do
begin
// IdHTTP 设置
HTTPOptions := HTTPOptions + [hoKeepOrigProtocol]; //保持 并使用PV1_1
ProtocolVersion := pv1_1;
HTTPOptions := HTTPOptions - [hoForceEncodeParams]; //去掉自动编码
AllowCookies := True;
HandleRedirects := True;
ConnectTimeout := 30000;
ReadTimeout := 30000;
// IdHTTP 提交信息的设置
Request.Accept := 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
Request.AcceptCharSet := 'GBK,gb2312,utf-8;q=0.7,*;q=0.3';
Request.AcceptEncoding := ''; //'gzip,deflate,sdch';
Request.AcceptLanguage := 'zh-CN,zh;q=0.8';
Request.Connection :='Keep-Alive';
Request.ContentType := 'application/x-www-form-urlencoded';
Request.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16';
Request.Referer := aURL;
SS_Response := TStringStream.Create('', TEncoding.GetEncoding(65001)); // TEncoding.UTF8
try
Get(aURL, SS_Response);
if ResponseCode <> 200 then Exit;
if SS_Response.Size <= 1 then Exit;
sWeb := SS_Response.DataString;
Result := True;
finally
FreeAndNil(SS_Response);
end;
end;
except
on E: Exception do
Result := False;
end;
finally
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
end;
end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。