Axios/XMLHttpRequest 在生产环境中发送 GET 而不是 POST [英] Axios/XMLHttpRequest is sending GET instead of POST in production environment

查看:39
本文介绍了Axios/XMLHttpRequest 在生产环境中发送 GET 而不是 POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常奇怪的问题.我们正在将一个应用程序投入生产,其中一个 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 slack 论坛上回答过,为了大家的利益,这里是下一个遇到此类问题的答案.

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/ 将不起作用.

So posting to https://example.com/post/to/ will not work.

删除 / 并发布到 https://example.com/post/to 即可.

Removing the / and posting to https://example.com/post/to will work.

这篇关于Axios/XMLHttpRequest 在生产环境中发送 GET 而不是 POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆