delphi idhttp数据自动编码


本文整理自网络,侵删。

 
idhttp数据自动编码
  RT。idhttp的httpOption,默认为[hoForceEncodeParams],即自动编码参数,但是idhttp自动编码有点小问题,如果参数中有" (空格)",会转成“+”,有加号会转成“ (空格)”,问题来了,如果我想提交一个参数,值为一个MD5值(MD5中很可能有“+”),在自动编码过程中,加号被编码成空格,最终导致参数错误。所以,post参数最好还是自己用函数编码,这样比较放心,附上urlEncode函数:

复制代码
function EncodeURL(const InputStr: string): string;
var
  Idx: Integer;
begin
  Result := '';
  for Idx := 1 to Length(InputStr) do
  begin
    case InputStr[Idx] of
      'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
        Result := Result + InputStr[Idx];
      ' ':Result := Result + '%20';
      '+':Result := Result + '%2B';
    else
      Result := Result + '%' + SysUtils.IntToHex(Ord(InputStr[Idx]), 2);
    end;
  end;
end;

相关阅读 >>

Delphi 获取大于2g的物理内存大小

Delphi base64, quoted-printable 的解码与编码函数

Delphi incyear、incmonth、incweek、incday、inchour、incminute、incsecond、incmillisecond �c 增时

Delphi编写涂鸦桌面的小程序

Delphi inttostransi

Delphi 控制memo1滚动条

Delphi 通过系统api函数实现精确记时

Delphi 中showmodal与show的区别

Delphi fdconnection1 获取数据库总记录数

Delphi 生成不重复数字随机码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...