wx.request不带session,封装了header后,向服务器传中文乱码

发布于 6 年前作者 fang726784 次浏览最后编辑 6 年前来自 ask

原来是这样封装header后,向服务器传送中文就不会是乱码了

 header: { ‘content-type’: ‘application/x-www-form-urlencoded’ }

但是因为request不带session,所以自己登陆的时候向服务器索取了sessionid,

重新封装了header,如下

 var session_id = wx.getStorageSync(‘session_id’);

    console.log(‘session_id’,session_id);

    if (session_id != “” && session_id != null) {

      var header = { ‘content-type’: ‘application/x-www-form-urlencoded’, ‘Cookie’: ‘JSESSIONID=’ + session_id }

    } else {

      var header = { ‘content-type’: ‘application/x-www-form-urlencoded’ }

    }  

    return header;

 但是这样封装了以后,再向后台传送中文,就又是乱码了,求知道的给说下,谢谢!

1 回复
ayu
ayu1 楼4 年前

自己解决了,要加上method:post