2017-10-14 105 views
2

我有反应+ redux客户端和C#API。我目前正试图在反应中实现删除方法。Axios.Delete()没有执行那么既没有catch块

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); 
    } 

,当我在铬调试它,我可以看到,那么,不执行catch块。请求没有被我的C#控制器捕获。

当我用邮递员尝试相同的请求时,请求正常被捕获到API中。

如果我把URL作为一个硬编码字符串 axios.delete('http://localhost:1467/v1/patients/11')

你能告诉我发生了什么(不会发生),这甚至不工作?

注:get方法是否正确

+0

如果你用邮递员运行相同的请求,它工作吗? – Freez

+0

是的,我在我的问题中告诉过它。 – pandemic

+0

对不起,我读得太快了......你在Chrome网络督察中看到了什么? – Freez

回答

1

工作有了巨大的感谢我的朋友我张贴的工作方案。我错过了默认标题。邮差是通过插入默认标题,与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)); 
     });    
}