使用 idHTTP 获取 UTF-8 编码的中文网页

转自万一老师的博客,网上有很多方法,均测试无效后有问题,测试这个方法是真正准确可行的:)

uses
IdHTTP;

const Url = 'http://del.cnblogs.com';

procedure TForm1.Button1Click(Sender: TObject);
var
  stream: TStringStream;
  idHttpObj: TIdHTTP;
begin
  stream := TStringStream.Create('', TEncoding.UTF8); //

  idHttpObj := TIdHTTP.Create(nil);
  idHttpObj.Get(Url, stream);
  idHttpObj.Free;

  Memo1.Text := stream.DataString;
  stream.Free;
end;
posted @ 2012-01-07 15:40  Handll  阅读(305)  评论(0编辑  收藏  举报