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编码格式即会正常,不会出现乱码的情况

  • 相关阅读:
    git取消文件跟踪
    servlet
    查杀端口进程
    初始化git仓库,并push到远端
    tomcat
    bootstrap
    idea中web工程错误
    i++和++i
    js算法
    编程工具
  • 原文地址:https://www.cnblogs.com/ab0416/p/4112156.html
Copyright © 2011-2022 走看看