码迷,mamicode.com
首页 > Web开发 > 详细

Idhttp Get方法

时间:2014-11-21 10:33:55      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   div   

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

Idhttp Get方法

标签:style   blog   http   io   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/ab0416/p/4112156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!