axios.put('http://1.1.1.1:1010/api/data', {
data: {
ip: '123123',
smth: true
},
headers: {
'content-type': "application/json ",
'Access-Control-Allow-Origin': '*',
},
}).then(res => {
console.log(res)
}).catch(error => {
console.log(error);
})
我收到了
Error: Request failed with status code 500
获取请求可以正常工作。我尝试没有成功:
headers: {
'content-type': "application/json ",
'Access-Control-Allow-Origin': '*',
},
data: {
ip: '123123',
dhcp: true
},
withCredentials: true,
crossdomain: true,
proxy: {
host: 'http://1.1.1.1',
port: 1010
},
validateStatus: (status) => {
return true;
},
在最后一行的后端错误中::
json_data = request.get_json(force=True)
accountGuid = 'DummyAccount'
pdict = json_data[self.tableName]
请帮帮我。我不知道该怎么办
答案 0 :(得分:0)
好的,我不确定这背后的逻辑是什么,但是最近发生在我身上。 我有一个put请求,该请求给了我500个内部服务器错误,但在邮递员上,相同的请求可以正常工作。
这是解决此问题的原因。 axios有两种发送请求的方式。
axios.put(url,body,config);
和
axios(request object);
我正在共享我的代码。也许对您也有帮助。
请求在此代码处失败。
const { data } = await axios.put(`trainer-schedule/cancel-appointment-student/${id}`, null, {
headers: {
'Authorization': 'Bearer ' + await AsyncStorage.getItem('auth_token'),
'Access-Control-Allow-Origin': '*',
}
});
我只是将其更改为其他方式,并且开始工作。
const { data } = await axios({
url: `trainer-schedule/cancel-appointment-student/${id}`,
headers: {
'Authorization': 'Bearer ' + await AsyncStorage.getItem('auth_token'),
'Access-Control-Allow-Origin': '*',
},
method: 'put'
});
我的环境是react-native,后端express js。
我建议您始终在邮递员上测试您的请求。它是测试api的最佳工具。但是发生在我身上的情况很少见。
希望对您有帮助。