【问题标题】:Laravel The GET method is not supported for this routeLaravel 该路由不支持 GET 方法
【发布时间】:2020-11-27 14:08:15
【问题描述】:

我有 laravel-vue 应用程序,我的一个功能在发布请求时运行,但奇怪的是我收到 GET 请求错误:

此路由不支持 GET 方法。支持的方法:POST。

代码

Route

Route::post('distanceCost', 'Api\Front\CartController@distanceCost');

Component

sendShippingRequest() {
    // post request
    axios.post('/api/distanceCost/', this.form, {
        headers: {
            Authorization: 'Bearer ' + localStorage.getItem('access_token')
        }
    })
    .then(response => {
        //....
    })
    .catch((error) => {
        console.log('error', error);
    });
}

有什么想法吗?

【问题讨论】:

  • /api/distanceCost/ 更改为 /api/distanceCost
  • @STA 相同的结果
  • @STA 坚持一下,我想我需要重新运行npm run prod 以获得结果
  • 很高兴听到它有效

标签: laravel vue.js vuejs2 axios


【解决方案1】:

问题是,为了响应对 /api/distanceCost/ 的 POST,Laravel 会重定向到 /api/distanceCost。然后,您的浏览器将向/api/distanceCost 发送请求,但这一次,它将使用 GET 并且不会发送 post 有效负载。这就是您的服务器回复错误代码的原因。

【讨论】:

    猜你喜欢
    • 2019-10-12
    • 2020-02-07
    • 1970-01-01
    • 2021-04-08
    • 2019-12-28
    • 2021-04-11
    • 2021-12-18
    • 2021-08-05
    • 2020-04-03
    相关资源
    最近更新 更多