Axios/XMLHttpRequest在生产环境中发送GET而不是POST [英] Axios/XMLHttpRequest is sending GET instead of POST in production environment
问题描述
我遇到了一个非常奇怪的问题.我们正在将一个应用程序投入生产,其中一个POST请求变成了一个POST,然后直接是对相同URL的GET请求,并且在后端(Laravel)从未收到POST.在chrome网络标签中,它看起来就像是GET,但通过Burpsuite,我们可以看到POST请求.
I am running into a very strange issue. We are putting an app into production and one of the POST request is turning into a POST followed directly by a GET request to the same URL and the POST is never received in the backend (Laravel). In the chrome network tab it just looks like just a GET but with Burpsuite we can see the POST request.
负责代码
async store() {
// This prints post
console.log(this.method());
await this.form[this.method()]('/api/admin/users/' + (this.isUpdate() ? this.id : ''));
if (!this.isUpdate()) {
this.form.reset();
}
},
form.post方法的内容
The form.post method content
return new Promise((resolve, reject) => {
axios[requestType](url, this.data())
.then(response => {
this.busy = false;
this.onSuccess(response.data);
resolve(response.data);
})
.catch(error => {
this.busy = false;
if (error.response.status == 400) {
return this.displayErrors(error.response.data)
}
this.onFail(error.response.data.errors);
reject(error.response.data);
});
});
推荐答案
我也在Larachat松弛论坛上回答了这个问题,出于其他原因,这是下一个有此问题的人的答案.
This question was also answered by me in the Larachat slack forum, and for others sake here is the answer for the next one with such a problem.
只是一个小故事.在聊天中,我们发现它收到301错误,这是重定向错误. 最近在发布到登台服务器上的URL时出现了相同的错误,它在本地运行良好,但在登台服务器上却无法正常工作.
Just a little back story. In the chat we found out that it was receiving a 301 error which is a redirect error. I had the same error recently when posting to a url on a staging server, it was working fine locally but not on the staging server.
问题似乎是帖子网址末尾的斜杠.
The problem appeared to be a slash at the end of the post url.
因此无法发布到https://example.com/post/to/
.
删除/
并将其发布到https://example.com/post/to
将起作用.
Removing the /
and posting to https://example.com/post/to
will work.
这篇关于Axios/XMLHttpRequest在生产环境中发送GET而不是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!