使用post请求数据存在但是无法传到后端
目录
使用post请求数据存在但是无法传到后端
1.请求头设置问题:
确保请求头中的Content-Type设置为application/x-www-form-urlencoded,这样后端能正确解析请求体中的数据。
在uni.request()中,可以通过设置header属性来指定请求头,确保Content-Type正确设置。
#header: {
‘content-type’: ‘application/x-www-form-urlencoded’
}#
2.数据编码问题:
确保请求体中的数据经过正确的URL编码。你可以使用JavaScript的encodeURIComponent()函数对参数进行编码。
#data: ‘actionCode=’ + encodeURIComponent(that.actionCode) +
‘&gunNo=’ + encodeURIComponent(that.gunNum) +
‘&startTime=’ + encodeURIComponent(that.startTime) +
‘&terminalCode=’ + encodeURIComponent(that.terminalCode)#
3.注意修改请求方式
#method: ‘POST’,#