Delphi的URLEncode

来源:互联网 发布:淘宝企业店铺有什么用 编辑:程序博客网 时间:2024/06/06 15:03
uses HTTPApp;function URLEncode(const AStr: string): string;const  NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '#', '$', '.', '_', '-', ':', '/', '&', '=', '?'];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;