charleslo1 / weapp-cookie

一行代码让微信、头条、百度、支付宝小程序支持 cookie,兼容 uni-app 🍪🚀 One line of code allows weapp to support cookie(wx weixin wxapp cookie)
MIT License
829 stars 98 forks source link

cookie中有中文的时候,header中会报错,请问如何处理比较好 #11

Closed BigPiter closed 5 years ago

BigPiter commented 5 years ago

当cookie中有中文的时候,header中会报错,请问如何处理比较好

charleslo1 commented 5 years ago

具体报什么错呢,能把异常信息贴出来吗?

BigPiter commented 5 years ago

服务器返回的cookie是这样的:558bgS%2BwI%2FtCQOdtV4XAumOOMLmtn7ZUjnq6ech2TeLwvJ%2FhAAgyblb9LRkCHXRZws%2FLTFmfz9503%2FpS1u0eLw

但是我们传过去的cookie是这样的: 558bgS+wI/tCQOdtV4XAumOOMLmtn7ZUjnq6ech2TeLwvJ/hAAgyblb9LRkCHXRZws/LTFmfz9503/pS1u0eLw 导致验证不通过 好像是特殊的 + 和 / 这个怎么处理啊

charleslo1 commented 5 years ago

编码问题,在接收端拿到 cookie 后进行URI解码就可以了,比如:

var value = decodeURIComponent('558bgS%2BwI%2FtCQOdtV4XAumOOMLmtn7ZUjnq6ech2TeLwvJ%2FhAAgyblb9LRkCHXRZws%2FLTFmfz9503%2FpS1u0eLw')
BigPiter commented 5 years ago

感谢,已经解决了