zoukankan      html  css  js  c++  java
  • Idhttp Get方法

    idhttp.get(AURL:string):string;//返回字符串

    idhttp.get(AURL:string;AResponseContent: TStream)//返回流

    基于网站的不同编码格式,第二种返回流的更加适用

     1 function httpGetByStr(Url: string): string;
     2 begin
     3     FIdhttp := TIdHTTP.Create(nil);
     4   try
     5     FIdhttp.ConnectTimeout := 3000;
     6     FIdhttp.ReadTimeout := 6000;
     7     Result := FIdhttp.Get(Url);
     8   finally
     9     FIdhttp.Disconnect;
    10     FreeAndNil(FIdhttp);
    11   end;
    12 end;
     1 function TSearchLrcThread.httpGetByStream(Url: string; AEncoding: TEncoding)
     2   : TStringStream;
     3 begin
     4     Result := TStringStream.Create('', AEncoding);
     5     FIdhttp := TIdHTTP.Create(nil);
     6   try
     7     FIdhttp.ConnectTimeout := 3000;
     8     FIdhttp.ReadTimeout := 6000;
     9     FIdhttp.Get(FUrl, Result);
    10   finally
    11     FIdhttp.Disconnect;
    12     FreeAndNil(FIdhttp);
    13   end;
    14 end;

     基于Unicode版本,根据网站的不同编码设置不同的AEncoding.类型即可,返回的Datastring编码格式即会正常,不会出现乱码的情况

  • 相关阅读:
    Ural 1966 Cycling Roads
    SQL Server 2008 安装(lpt亲测)
    cf Round#273 Div.2
    poj 2318 TOYS
    计算几何好模板
    ❤Friends
    限制pyqt5应用程序 只允许打开一次
    pyqt5 菜单栏+信息提示框
    Android Linux deploy
    system分区解锁
  • 原文地址:https://www.cnblogs.com/ab0416/p/4112156.html
Copyright © 2011-2022 走看看