流明抛出405不允许的方法上获取途径

问题描述 投票:3回答:4

我无法理解为什么我收到405以下

$app->group(['prefix' => 'api/v1'], function($app)
{
    $app->get('my','MyController@index');
    $app->post('my','MyController@store');
});

帖子的网址是否运作正常,但是当我拿到定义路由应用开始扔我405。

URL呼叫秀

in RoutesRequests.php line 596
at Application->handleDispatcherResponse(array(2, array('POST'))) in RoutesRequests.php line 533
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 781
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 534
at Application->dispatch(null) in RoutesRequests.php line 475
at Application->run() in index.php line 28

帖子的网址工作正常,它只是在获取URL抛出405 ...清除缓存,生成的文件自动加载...不知道自己做错了什么..

定义一个新的路线新的控制器和它抛出404 ......我没有看到它作为一个路线问题上没有别的东西..

laravel lumen lumen-5.3
4个回答
1
投票

这是因为,你是在试图访问具有POST方法的路线,或者你正在使用张贴POST方法的数据,到具有GET方法途径。

检查你的路线和形式。


0
投票

我尝试了情景为,是和它的作品。你有没有调试呢?如果您在.env文件去,检查是否APP_DEBUG变量设置为true

一旦完成后,尝试加载页面,并张贴您看到的错误。

PS:另外检查是否MyController控制器已创建。


0
投票

只是有同样的行为,像花了一个小时试图解决它。

最后,它是在GET查询斜线。


0
投票

它是由您的中间件造成不处理OPTIONS请求

您的中间件应该是这样的:

class CorsMiddleware
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{
    //Intercepts OPTIONS requests
    if ($request->isMethod('OPTIONS')) {
        $response = response('', 200);
    } else {
        // Pass the request to the next middleware
        $response = $next($request);
    }

    // Adds headers to the response
    $response->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, PATCH, DELETE');
    $response->header('Access-Control-Allow-Headers', $request->header('Access-Control-Request-Headers'));
    $response->header('Access-Control-Allow-Origin', '*');
    $response->header('Access-Control-Expose-Headers', 'Location');

    // Sends it
    return $response;
}
}

https://github.com/laravel/lumen-framework/issues/674

© www.soinside.com 2019 - 2024. All rights reserved.