微信小程序系列-wx.request POST请求中文乱码问题

问题:

今天做小程序的一个表单提交,有字段包含中文,在提交的过程中,查看数据库出现乱码。查找原因 是在后台接口接接收值的时候乱码了。

 method: "post", //可以设置不同方式   如:get等
  header: { 'content-type': 'application/x-www-form-urlencoded' },

原因:

如果设置content-type: application/x-www-form-urlencoded ,微信默认会为键值对进行Url编码,也就是说微信默认会为key-value 加上urlEncode,所以服务端要将键值对进行urlDecode

解决办法:

 method: "post", //可以设置不同方式   如:get等
 header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },

你可能感兴趣的:(微信小程序系列-wx.request POST请求中文乱码问题)