Python代码是:
user = "aabc"
password = "yyy12%"
data = urllib.urlencode({"loginname": user, "nloginpwd": password})
print data
结果是:loginname=aabc&nloginpwd=yyy12%25
为什么要在字符串末尾添加 25
?
最佳答案
%
字符在 URL 中具有特殊含义;它用于启动转义序列。查看Percent-encoding article在维基百科上。 literal %
也必须进行编码,%25
是编码后的版本。来自维基百科页面:
Because the percent (
"%"
) character serves as the indicator for percent-encoded octets, it must be percent-encoded as"%25"
for that octet to be used as data within a URI.
换句话说,%25
是一个编码的 %
字符。
关于python - 为什么 urllib.urlencode 将 "25"附加到结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002871/