問題:
一個簡單的表單,提交后台返回數據“提交成功”。
以為沒問題了,但是沒過多久后台小哥就問為啥那么多亂碼,找了很久原因,發現在提交的時候就已經亂碼了。
嗯,前端問題,然后測試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',}