UrlEncode 函数

欢迎加入全网最大Delphi 技术交流群 682628230
function UrlEncode(CONST URL: string): string; { It also fixes the Indy encoding issue. http://stackoverflow.com/questions/5708863/indy-is-altering-the-binary-data-in-my-url }
VAR
i: Integer;
CONST
UnsafeChars = ['*', '#', '%', '<', '>', ' ', '[', ']', '\', '@'];
begin
Result := '';
for i := 1 to Length(URL) DO
if (URL[i]> #32)
AND (URL[i]<= #128) { € = char #128}
AND (NOT CharInSet(URL[i], UnsafeChars))
then Result := Result + URL[i]
else Result := Result + '%' + IntToHex(Ord(URL[i]), 2);
end;

 

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享