使用以下代码转换中文。 function HTMLEncode(const AStr: String): String; const NoConversion = ['A'..'Z','a'..'z','*','.','_','-','0'..'9','!','''','(',')']; //不需要进行转换的字符。 var Sp, Rp: PChar; begin SetLength(Result, Length(AStr) * 3); Sp := PChar(AStr); Rp := PChar(Result); while Sp^ <> #0 do begin if Sp^ in NoConversion then Rp^ := Sp^ else if Sp^ = ' ' then Rp^ := '+' else begin FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]); Inc(Rp,2); end; Inc(Rp); Inc(Sp); end; SetLength(Result, Rp - PChar(Result)); end;
转换成
Data=#BA#C3
然后再Post
const
NoConversion = ['A'..'Z','a'..'z','*','.','_','-','0'..'9','!','''','(',')']; //不需要进行转换的字符。
var
Sp, Rp: PChar;
begin
SetLength(Result, Length(AStr) * 3);
Sp := PChar(AStr);
Rp := PChar(Result);
while Sp^ <> #0 do
begin
if Sp^ in NoConversion then
Rp^ := Sp^
else
if Sp^ = ' ' then
Rp^ := '+'
else
begin
FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]);
Inc(Rp,2);
end;
Inc(Rp);
Inc(Sp);
end;
SetLength(Result, Rp - PChar(Result));
end;
然后再POST前转换一下!