MethodNotAllowedHttpException (lumen) while making request with axios

ぃ、小莉子 提交于 2021-02-07 10:53:54

问题


Created a route for inserting todo in lumen , its working perfectly using postman but in my react application request sending with axios , it getting error

this.apiUrl = 'http://lumenback.dev/createTodo';

axios.post(this.apiUrl, {
  todo: this.state.todo,
  todo_date: this.props.curDate
})
.then(function (response) {
  console.log(response);
}).catch(function (error) {
  console.log(error);
});

thanks in advance...


回答1:


Your application is not accepting the Cross domain requests I guess.

Here is an answer Lumen API CORS Ajax 405 Method Not Allowed I wrote to setup Cors and make it working with React and Lumen 5.5.

See if this can help.

I cannot comment so writing this solution here.




回答2:


This is a stab in the dark, but have you tried setting the headers on axios first?

Insert this before your post command: axios.defaults.headers.post["Content-Type"] = "application/json";



来源:https://stackoverflow.com/questions/47016248/methodnotallowedhttpexception-lumen-while-making-request-with-axios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!