这是一件非常奇怪的事情:
我在Laravel 5中实现了Iron消息队列,以便将请求与长任务执行区分开来。 一旦我将消息推送到Iron的队列中,它就会向预定义的路由发送POST请求,以便唤醒长时间运行的进程(推送队列方法)。
我有这个路线档案:
Route::post('queue/receive', function()
{
//start long task exec
return Queue::marshal();
});
/* garantisco il logout agli utenti*/
Route::get('auth/logout', 'Auth\AuthController@getLogout');
/* redirect degli utenti loggati */
Route::group(['middleware' => 'guest'], function()
{
Route::get('/', 'WelcomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
});
Route::group(['middleware' => 'auth'], function()
{
Route::get('home', 'HomeController@index');
});
定义的第一个路由是IronMQ将调用的端点。 我知道令牌不匹配是一个流行的问题,使用" VerifyCsrfToken"中间件(与L4中的过滤器相同)。 令人难以置信的是,我已经禁用了这个中间件,但问题仍然存在。 这是我内核的中间件:
class Kernel extends HttpKernel {
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
//'LabelCreator\Http\Middleware\VerifyCsrfToken',
];
/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => 'LabelCreator\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'LabelCreator\Http\Middleware\RedirectIfAuthenticated',
];
}
正如您所见," VerifyCsrfToken"已禁用,但测试来自本地环境的帖子请求,现在我收到此错误:
DecryptException in Encrypter.php line 142:
Invalid data.
in Encrypter.php line 142
at Encrypter->getJsonPayload('') in Encrypter.php line 92
at Encrypter->decrypt('') in IronQueue.php line 214
at IronQueue->parseJobBody('') in IronQueue.php line 173
at IronQueue->marshalPushedJob() in IronQueue.php line 159
at IronQueue->marshal()
at call_user_func_array(array(object(IronQueue), 'marshal'), array()) in QueueManager.php line 223
at QueueManager->__call('marshal', array()) in Facade.php line 207
at QueueManager->marshal() in Facade.php line 207
at Facade::__callStatic('marshal', array()) in routes.php line 17
at Queue::marshal() in routes.php line 17
at RouteServiceProvider->{closure}()
at call_user_func_array(object(Closure), array()) in Route.php line 153
at Route->runCallable(object(Request)) in Route.php line 128
at Route->run(object(Request)) in Router.php line 691
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 693
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
我试图评论其他中间件,但问题仍然存在。 Iron正在做的是对我的端点的简单POST请求,就像webhooks一样。 问题是什么? 我认为这不是一个会话问题,因为Iron是一个简单的第三部分服务,可以调用一个端点,如果它仍然是一个" guest"我的应用程序的客户端没问题。
任何人都可以帮助我吗? 提前谢谢
答案 0 :(得分:0)
我发现了这个问题: 我在没有POST请求有效负载的情况下在本地测试端点,因此解密无法正常工作,但使用RequestBin(非常有用的工具)嗅探IronMQ发送的有效负载,我已经添加了与本地测试请求相同的有效负载,现在可以正常工作。
希望有所帮助:)