delphi idhttp数据自动编码  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.035351991653442 seconds