问题:

  一个简单的表单,提交后台返回数据“提交成功”。

  以为没问题了,但是没过多久后台小哥就问为啥那么多乱码,找了很久原因,发现在提交的时候就已经乱码了。

  嗯,前端问题,然后测试GET/POST方法。GET没有乱码,POST乱码

  header这样写的    header: { 'content-type': 'application/x-www-form-urlencoded' }

 

  原因:

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

 

  解决方法:

  设置header    header:{'content-type': 'application/x-www-form-urlencoded;charset=utf-8',}

相关文章:

  • 2022-12-23
  • 2021-10-28
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-07-23
猜你喜欢
  • 2021-10-06
  • 2021-12-18
  • 2021-11-02
  • 2022-01-22
  • 2021-05-31
  • 2021-12-21
  • 2022-12-23
相关资源
相似解决方案