4

我不明白为什么我在下面得到 405

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

post url 按预期工作,但是当我定义 get route 时,应用程序开始向我抛出 405 。

来电显示

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

post url工作正常,只是get url抛出405 ...清除缓存,生成自动加载文件...不知道出了什么问题..

用新路由定义新控制器,它会抛出 404 ......我不认为它是一个路由问题,还有别的东西..

4

4 回答 4

4

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

最后它是 GET 查询中的斜杠。

于 2017-06-07T13:34:27.337 回答
2

这是因为,您正在尝试访问具有 POST 方法的路由,或者您正在使用 POST 方法发布数据,以访问具有 GET 方法的路由。

检查您的路线和表格。

于 2017-05-03T11:01:26.817 回答
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

于 2019-02-09T22:44:45.290 回答
0

我按原样尝试了这个场景并且它有效。你有调试吗?如果您进入.env文件,请检查APP_DEBUG变量是否设置为true.

完成后,尝试加载页面并发布您看到的错误。

PS:还要检查MyController控制器是否已创建。

于 2017-05-02T20:19:58.737 回答