通过URL传递base64编码的问题

56 篇文章 0 订阅
通过URL传递base64编码的问题
因为标准的base64编码结果包含"+" 和 “/”,在通过URL传递到服务器时,会被转成空格,造成不能获得正确的解码结果。
所以必须要将 base64 编码后的字符串中的 "+"  替换成 %2B 才能当作 URL 参数进行传递。
在测客户的一个java的应用时,遇到这个问题的。
回想一下自己刚用python做的应用,也用到了base64编码,返回去调查了下。发现python 的base64模块已经解决此问题。
它提供了一个参数,去作这种替换。
b64encode( s[, altchars])
Encode a string use Base64.

s is the string to encode. Optional altchars must be a string of at least length 2 (additional characters are ignored) which specifies an alternative alphabet for the + and / characters. This allows an application to e.g. generate URL or filesystem safe Base64 strings. The default is None, for which the standard Base64 alphabet is used.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值