Php 拉威尔5.4 API路线

Php 拉威尔5.4 API路线,php,post,laravel-5,routes,Php,Post,Laravel 5,Routes,我的web路由正在工作,但是我无法发布到我的api路由,我收到MethodNotAllowedHttpException。我认为这是一个csrf令牌问题,但我不知道如何解决它。我使用Postman来模拟api请求 auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [

我的web路由正在工作,但是我无法发布到我的api路由,我收到
MethodNotAllowedHttpException
。我认为这是一个csrf令牌问题,但我不知道如何解决它。我使用Postman来模拟api请求

auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'devices',
    ],
],
RouteServiceProvider.php

protected function mapApiRoutes()
{
    Route::middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}
routes/api.php

Route::post('api', ['uses' => 'DeviceController@api']);
kernel.php

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        // \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

    'api' => [
        'throttle:60,1',
        'auth:api',
        'bindings',
    ],
];

这是从运行中的旧版本Laravel的升级,我通过安装Laravel 5.4的新副本进行升级,然后复制我的代码,根据需要进行更改。

Send
\u token
使用POST请求发送这样的值

    $.ajax({
        type: "POST",
        url: "/your url",
        data: {_token:$("input[name='_token']").val(),'other':'Other value'}
    }).done(function( response ) {
        ....
    });

对不起,我一个月前犯了同样的错误。问题是我没有使用https。奇怪的是,我是如何得到方法的。我想这让我很反感。

你是从哪里打电话来的?如果来自ajax的用户共享该代码?@detective404,我将使用Postman来完成此调用。我打电话给www.mydomain.com/api,并发出了一个帖子请求hey@meeeee您找到这个问题的解决方案了吗。我也有类似的问题,如果它在你身边解决了,那就让我知道。@DenisBhojvani是的,我知道了。当我强制使用https时,我试图使用http。这在使用api时对我来说没有意义。不需要令牌您正在调用哪个url?您需要在kernel.php中注释
\App\Http\Middleware\VerifyCsrfToken::class,
,以不进行验证,因为您无法从postmanI发送
\u令牌
值,因为我需要令牌来处理网站的web部分。我确实尝试将api路由添加到csrf令牌中,方法除外,但没有帮助。这可能根本不是一个象征性的问题。谢谢你试图帮助聪明的X'D喜欢诚实:p