问题
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