先看一个例子
procedure TForm1.Button1Click(Sender:
TObject);
var
Response2: TStringStream;
S : string;//注意必须是string
,网上说的widestring 执行空白
begin
IdHTTP1.HandleRedirects:=true;
Response2 :=
TStringStream.Create('');
idhttp1.Head(edit1.text);
idhttp1.Request.ContentType :=
'application/x-www-form-urlencoded';
idhttp1.Get(edit1.text,Response2);
S:=Response2.DataString;
S := Utf8ToAnsi(S);
TNTMemo1.lines.Text:= S;
Response2.Free;
end;
其中的 utf8 是一种常用的 unicode
编码方式,在目前的网络环境中应用最广,特别是在java,xml这种国际化很强的地方.delphi并不支持原生的utf8字符串,它对
unicode 的支持则是非常好了.将普通字符串赋值给 String 类型即可.而对 uft8 则要用到上面所说的Utf8ToAnsi
等转换函数.好在这些函数都很容易使用,只是大家在使用时要注意自己当前操作的字符串是什么类型就行了.类似的函数还有
AnsiToUtf8
UTF8Decode
Utf8ToAnsi
UTF8Decode
UTF8Encode