POST from external server issue on Laravel

两盒软妹~` 提交于 2019-12-23 05:27:48

问题


I am doing a post from an external server to my Laravel app and it is throwing this exception on app/filters/policy.php: Illuminate\Session\TokenMismatchException.

This is my app/filters/policy.php:

Route::filter('csrf', function()
{
    $token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token');

    if (Session::token() != $token)
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
});

And this is my app/route.php:

Route::any('webservice', ['uses' => 'WebserverController@postWebservice']);

I think it is because the CSRF filter is applied to all routes, but I don't know how to disable it to /webservice.

I'd appreciate any help.


回答1:


Maybe you may try something like this:

if(Request::url() != 'http://example.com//webservice') {
    $token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token')
    if (Session::token() != $token) {
        throw new Illuminate\Session\TokenMismatchException;
    }
}


来源:https://stackoverflow.com/questions/22873912/post-from-external-server-issue-on-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!