laravel - Axios/XMLHttpRequest 在生产环境中发送 GET 而不是 POST

标签 laravel post get xmlhttprequest axios

我遇到了一个非常奇怪的问题。我们正在将一个应用程序投入生产,其中一个 POST 请求正在转换为 POST,然后直接对同一 URL 发出 GET 请求,并且后端 (Laravel) 永远不会收到 POST。在 chrome 网络选项卡中,它看起来只是一个 GET,但使用 Burpsuite 我们可以看到 POST 请求。

负责的代码

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方法内容

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论坛上回答过,为了其他人的缘故,这里是下一个有这样问题的答案。

只是一个小背景故事。在聊天中我们发现它收到了 301 错误,这是一个重定向错误。 我最近在发布到临时服务器上的网址时遇到了同样的错误,它在本地工作正常,但在临时服务器上却不起作用。

问题似乎是帖子网址末尾的斜线。

因此发布到 https://example.com/post/to/ 将不起作用。

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

关于laravel - Axios/XMLHttpRequest 在生产环境中发送 GET 而不是 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47208440/

相关文章:

php - 为什么本应该发布公司名称却发布 ID?

jquery - 如何获取 GET 请求中函数中使用的变量的值?

c# - C# 中的 getter 和 setter 有什么用?我如何将它们与数组一起使用?

php - $_GET 无法正常工作

mysql - Eloquent 中的 IN 语句

php - Laravel Maatwebsite excel数组

node.js - 使用 Node 和 Mongoose 从数组中生成新的 mongoDB 文档的最佳方法是什么?

C# 将文件发布到服务器

php - Laravel 事件监听器和缓存不起作用

php - Laravel( Eloquent )不更新数据库