Axios.Delete() 不执行然后两个 catch 块
Axios.Delete() not executing then neither catch block
我有 React + redux 客户端和 C# API。我目前正在尝试在 React 中实现 delete 方法。
patients.js
deletePatient(patientId) {
debugger;
axios.delete(url + 'patients/' + patientId).then(res =>
{
this.props.dispatch(deletePatientAction(res));
})
.catch( function(error) {
console.log(JSON.stringify(error, null, 2));
});
}
PatientController.cs
[HttpDelete]
public HttpResponseMessage Delete(int id)
{
patientTasks.Delete(id);
return Request.CreateResponse(HttpStatusCode.OK);
}
当我在 chrome 中调试它时,我可以看到 then 和 catch 块没有被执行。该请求未在我的 C# 控制器上被捕获。
当我尝试使用 Postman 发出相同的请求时,该请求正常被 API 捕获。
即使我将 url 作为硬编码字符串也不起作用
axios.delete('http://localhost:1467/v1/patients/11')
你能告诉我发生了什么(没有发生)吗?
注意:get 方法工作正常
非常感谢我的朋友,我发布了工作解决方案。我缺少默认值 headers。 Postman是通过插入默认的headers,加上axios
我得自己定义。
deletePatient(patientId) {
var config = {
headers: {
'User-Agent':'',
'Accept':'',
'Host':''
}
};
axios.delete(url + 'patients/' + patientId, config).then((res) =>
{
this.props.dispatch(deletePatientAction(res));
})
.catch( function(error) {
console.log(JSON.stringify(error, null, 2));
});
}
我有 React + redux 客户端和 C# API。我目前正在尝试在 React 中实现 delete 方法。
patients.js
deletePatient(patientId) {
debugger;
axios.delete(url + 'patients/' + patientId).then(res =>
{
this.props.dispatch(deletePatientAction(res));
})
.catch( function(error) {
console.log(JSON.stringify(error, null, 2));
});
}
PatientController.cs
[HttpDelete]
public HttpResponseMessage Delete(int id)
{
patientTasks.Delete(id);
return Request.CreateResponse(HttpStatusCode.OK);
}
当我在 chrome 中调试它时,我可以看到 then 和 catch 块没有被执行。该请求未在我的 C# 控制器上被捕获。
当我尝试使用 Postman 发出相同的请求时,该请求正常被 API 捕获。
即使我将 url 作为硬编码字符串也不起作用
axios.delete('http://localhost:1467/v1/patients/11')
你能告诉我发生了什么(没有发生)吗?
注意:get 方法工作正常
非常感谢我的朋友,我发布了工作解决方案。我缺少默认值 headers。 Postman是通过插入默认的headers,加上axios
我得自己定义。
deletePatient(patientId) {
var config = {
headers: {
'User-Agent':'',
'Accept':'',
'Host':''
}
};
axios.delete(url + 'patients/' + patientId, config).then((res) =>
{
this.props.dispatch(deletePatientAction(res));
})
.catch( function(error) {
console.log(JSON.stringify(error, null, 2));
});
}