打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
- IDHTTP GET网页通用函数
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;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
我用IDHTTP的get和post接收到的数据怎么解码啊。。
IdHTTP组件提交表单及登录源码(强制使用http 1.1)
DELPHI 调用淘宝API 例子
【原创】delphi应用程序自动升级取真实文件名方法
Delphi Post登陆Delphi盒子论坛源码
JSP九大内置对象
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服