本人想在网页中找出相关的链接(链接中有中文),当发现取出网页到字符串时就碰到中文问题。
要处理的网页编码是gb2312var s:string;
begin
idHttp1.Request.AcceptCharSet:='UTF-8';
s:=idHttp1.get('地址');
s:=idHttp1.Utf8Encode(s);
return s;
end;返回的s取出来了发现在后面用的时候的时候,网页内容不完整,而且中文显示不正确。所以想将s写入1.htmvar 
s:string;
htmlFile:TextFile;
begin
idHttp1.Request.AcceptCharSet:='UTF-8';
s:=idHttp1.get('地址');
s:=idHttp1.Utf8Encode(s);
try
    AssignFile(htmlFile,'d:/1.htm');
    Rewrite(htmlFile);
    Writeln(htmlFile,s);
  finally
    CloseFile(htmlFile);
  end;
end;
结果发现,s的代码是完整的,但是中文还是乱码。
通过几种方法都不能解决,
如:
with idHttp1 do
    begin
      Request.Accept := 'text/html, */*';
      Request.ContentLength := 0;
      Request.ContentRangeEnd := 0;
      Request.ContentRangeStart := 0;
      Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
      Request.ContentType := 'application/x-www-form-urlencoded';
      HandleRedirects := true;
    end;
编码:AnsiToUtf8(s)都不行
希望大家帮忙解决下,感激不尽。

解决方案 »

  1.   

    试过了,widestring 也不行,对了我用的是delphi2009
      

  2.   

    为什么需要idHttp1.Request.AcceptCharSet:='UTF-8'; 你的网页编码是gb2312,干嘛要用UTF-8呢。直接s:=idHttp1.get('地址'); 
      

  3.   

    去掉idHttp1.Request.AcceptCharSet:='UTF-8'; 
    还是没用,我试过的。
    再写入文件后,打开还是乱码。
    但是用TStream来保存一切正常。
      

  4.   

    结贴了,最后我还是用TMemoryStream读到TStringList里去的。
    对于编码还是稀里糊涂,希望大家提供点详细资料。