delphi2009中indy10的idhttp POST时中文乱码怎么办?

时间漩涡 2009-02-27 03:54:45
参考代码

  postParam:=TStringList.Create;
response:=TStringStream.Create('');
postParam.Add('Submit=登 录');
idHttp.Post('http://www.abc.com,postParam,
response);


抓包查看,Submit的结果为 v7B _55

在用delphi7的时候都正常。。结果也是 登录

在csdn里也找了其它相关的帖子,都没找到满意的答案,所以想提出来问问达人们的意见。。。请赐教!!!
...全文
2149 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengemail8 2011-06-23
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20110623/09/b67cdecb-1a6b-4b15-930a-45ade193866f.html
高人们,看一下这个贴子也是乱码
nieshiao 2011-06-13
  • 打赏
  • 举报
回复
AnsiChar,AnsiString
一剑飘雪 2011-06-13
  • 打赏
  • 举报
回复
高人啊 学习了
byyouxin 2010-03-15
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 seamour 的回复:]
try this:

Delphi(Pascal) code

type
ISO8859String = type AnsiString(1252);
GB2312String = type AnsiString(936);
function URIParamsEncode(const ASrc: RawByteString): RawByteString;
……
[/Quote]

高人啊 学习了
book_longker 2009-12-15
  • 打赏
  • 举报
回复
还是不懂
xjq2003 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 Seamour 的回复:]
try this:

Delphi(Pascal) code
type
ISO8859String = type AnsiString(1252);
GB2312String = type AnsiString(936);
function URIParamsEncode(const ASrc: RawByteString): RawByteString;
const
UnsafeChars = ['*', '#', '%', '<', '>', '[', ']'];
ASCIIChars = [#$21..#$7f];
AnsiHex : array[0..15]of AnsiChar = '0123456789ABCDEF';
var
i, len : Integer;
b : Byt…
[/Quote]
学习了!
Seamour 2009-02-27
  • 打赏
  • 举报
回复
try this:

type
ISO8859String = type AnsiString(1252);
GB2312String = type AnsiString(936);
function URIParamsEncode(const ASrc: RawByteString): RawByteString;
const
UnsafeChars = ['*', '#', '%', '<', '>', '[', ']'];
ASCIIChars = [#$21..#$7f];
AnsiHex : array[0..15]of AnsiChar = '0123456789ABCDEF';
var
i, len : Integer;
b : Byte;
c : AnsiChar;
sBuff : RawByteString;
pSrc, pDst : PAnsiChar;
begin
len := Length(ASrc);
if(ASrc[len]='&')then Dec(len);
SetLength(sBuff, len*3);
pSrc := Pointer(ASrc);
pDst := Pointer(sBuff);
for i := 0 to Len - 1 do
begin
c := pSrc[i];
if((c in UnsafeChars)or(not(c in ASCIIChars)))then
begin
b := Byte(c);
pDst[0] := '%';
pDst[1] := AnsiHex[b shr 4];
pDst[2] := AnsiHex[b and $f];
Inc(pDst, 3);
end else
begin
pDst^ := c;
Inc(pDst);
end;
end;
pSrc := Pointer(sBuff);
SetString(Result, pSrc, pDst-pSrc);
end;
var
lstPost : TStringList;
stmTmp : TMemoryStream;
sI8859 : ISO8859String;
sGb2312 : GB2312String;
begin
lstPost := TStringList.Create;
stmTmp := TMemoryStream.Create;
try
lstPost.Add('mobile='+Edit1.Text);
lstPost.Add('action=mobile');
lstPost.Add('test=测 试');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';

sGb2312 := URIParamsEncode( GB2312String(StringReplace(
lstPost.Text, #13#10, '&', [rfReplaceAll] )) );
stmTmp.Write(sGb2312[1], Length(sGb2312));
stmTmp.Position := 0;

sI8859 := ISO8859String(IdHTTP1.Post(URLPost, stmTmp));
SetString(sGb2312, PAnsiChar(sI8859), Length(sI8859));
Memo1.Text := string(sGB2312);
finally
stmTmp.Free;
lstPost.Free;
end;

只针对gb2312,需要自己确认编码是gb2312而不是其它的
hidelphi 2009-02-27
  • 打赏
  • 举报
回复
应该是UTF8编码有关吧
bdmh 2009-02-27
  • 打赏
  • 举报
回复
期待高人吧
时间漩涡 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bdmh 的回复:]
http://topic.csdn.net/u/20081009/14/6d5a608a-d473-4305-9445-c4f6c3016205.html
这个帖子的发贴人已经解决了,有个连接,你可以下载看看

http://download.csdn.net/source/836822
Delphi2009自带的INDY10修正文件!
[/Quote]

这个我看到过,但是不想修改自带的indy10。。。改了感觉怪怪的。。。
bdmh 2009-02-27
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20081009/14/6d5a608a-d473-4305-9445-c4f6c3016205.html
这个帖子的发贴人已经解决了,有个连接,你可以下载看看

http://download.csdn.net/source/836822
Delphi2009自带的INDY10修正文件!
时间漩涡 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bdmh 的回复:]
可以试试
[/Quote]

试过了,不行...用wideString也试过了。。
bdmh 2009-02-27
  • 打赏
  • 举报
回复
可以试试
时间漩涡 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bdmh 的回复:]
应该是字符类型不兼容,尽量使用带Ansi的类型,比如AnsiChar,AnsiString等
[/Quote]

你好,可以仔细解释一下吗?你的意思是我需要把 'Submit=登 录' 强制转成AnsiString吗?
bdmh 2009-02-27
  • 打赏
  • 举报
回复
应该是字符类型不兼容,尽量使用带Ansi的类型,比如AnsiChar,AnsiString等

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧