wx.request不带session,封装了header后,向服务器传中文乱码
发布于 4 年前 作者 fang72 6581 次浏览 来自 问答

原来是这样封装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 回复

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

回到顶部