将数据发送到服务器时遇到麻烦。我正在使用React Native和axios ver ^ 0.16.2
let input = {
'longitude': -6.3922782,
'latitude': 106.8268856,
'content': 'uget - uget sampai kaki lemes',
'pictures': []
}
axios({
method: 'POST',
url,
headers: {
'Content-Type': 'application/json',
'Authorization': this.state.headers.authorization
},
data: input
})
.then((resultAxios) => {
console.log('hasil axios', resultAxios)
})
状态结果总是错误500。
如果我尝试与 postman 发送数据,一切都很好。在 postman 中,我设定
headers: {
Authorization: ''',
Content-Type: application/json
}
body = raw, JSON
如何解决这个问题?谢谢 :)
最佳答案
我发现axios在处理body的json时有一些问题
试试这个:
let input = 'longitude=-6.3922782&latitude=106.8268856&content="uget - uget sampai kaki lemes"&pictures=[]';
axios({
method: 'POST',
url,
headers: {
'Content-Type': 'application/json',
'Authorization': this.state.headers.authorization
},
data: input
})
.then((resultAxios) => {
console.log('hasil axios', resultAxios)
})
状态结果总是错误500。
如果我尝试与 postman 发送数据,一切都很好。在 postman 中,我设定
headers: {
Authorization: ''',
Content-Type: application/json
}
body = raw, JSON