我已经在控制台中通过这个cmd启动了服务器,并且运行良好。
php -S localhost:8000 -t public当我在邮递员中调用API以获取这样的流明时:
localhost:8000/GitHub/twinfield/public/index.php/userAPI适用于insert,但当我像这样调用时:
localhost:8000/GitHub/twinfield/user错误如下:
(1/1) Application->handleDispatcherResponse(array(0)) in RoutesRequests.php (第226行)在RoutesRequests.php (第164行)在RoutesRequests.php中的NotFoundHttpException (第413行)在应用->在RoutesRequests.php (第166行)中发送通过管道(数组()、对象(闭包)在应用程序->调度(Null)在RoutesRequests.php (第107行)在应用->运行()在index.php (第28行)
我的路由文件在路由/web.php中:
$router->get('/', function () use ($router) {
//print_r('1234');die;
return $router->app->version();
});
$router->get('user','userController@index');
$router->get('user/{id}','userController@getuser');
$router->post('user','userController@createuser');
$router->post('user/{id}','userController@updateuser');
$router->delete('user/{id}','userController@deleteuser');我已经尝试过在public/index.php中解决这个问题,但没有成功。
$request = Illuminate\Http\Request::capture();
$app->run($request);我在本地和Xampp一起工作。数据库为MySQL,PHP为7.1。
发布于 2017-11-27 08:34:20
先生,您忘了网址链接,否则可能会错过。当我们启动服务器时(在laravel中,命令是php artisan serve),它总是属于从调用它的位置开始的路径。
就像在您的例子中一样,您的路径是xampp/htdocs/GItHub/twinfield (我想)。
localhost:8000/GitHub/twinfield/public/index.php/user所以如果你这样打电话:
localhost:8000/GitHub/twinfield/user它从未起作用,因为您定义了路由:
$router->get('user','userController@index');
$router->post('user','userController@createuser');这就是为什么您必须只使用路线和类型的名称。打开postman,用type->get添加这一行:
localhost:8000/user您将获得DB中的所有用户。如果使用类型->post添加这一行。
localhost:8000/user而不应该在要保存的表中的字段中发布body。
发布于 2017-11-24 06:54:58
经过多次尝试,我觉得自己犯了一个愚蠢的错误。这是网址:
localhost:8000/GitHub/twinfield/user因为新服务器是由命令启动的,所以它属于该url。所以我用这个网址在邮递员和get和比post。
localhost:8000/user你知道,它就像一种魅力。在这个解决方案中不需要其他任何东西。
https://stackoverflow.com/questions/47467156
复制相似问题