我正在使用OAuth2身份验证构建Lumen API,我遵循了本教程:http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/但我得到了一个错误:
"Fatal error: Maximum execution time of 60 seconds exceeded in C:\Users\user\Desktop\api\lumen\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php on line 99"
guzzle的post方法(还有get方法)对我不起作用

$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('localhost:8000/api/hello');
return $response;
});

$app->get('api/hello', function() use ($app) {
return "Hello";
});

给我同样的错误

最佳答案

我解决了我的问题:
从我的api到我的api的post和get请求不起作用,因为我正在使用

php artisan serve

所以localhost:8000/api对localhost:8000/api/hello的请求不起作用,但是在http://www.google.com/上从localhost:8000/api获得请求。
例子:
$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('http://www.google.com/');
return $response;
});

我不得不将lumen api直接部署到本地主机的www/文件夹中(在windows上是c:\ wamp\www,在linux上是/var/www/html/)
$app->get('api', function() use ($app) {
$client   = new \GuzzleHttp\Client();
$response = $client->get('localhost/api/hello');
return $response;
});

$app->get('api/hello', function() use ($app) {
return "Hello";
});

现在它开始工作了。
对于那些不知道如何在本地主机(或服务器)上部署Lumen API的用户:
我的Lumen项目位于C:\ wamp\www\api
在项目根目录中创建一个.htaccess,使其路径为C:\wamp\www\api\.htaccess
具有
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>

将C:\ wamp\www\api\server.php重命名为C:\ wamp\www\api\index.php
在您的c:\wamp\www\api\public\index.php中
改变
$app->run();

具有
$request = Illuminate\Http\Request::capture();
$app->run($request);

别忘了激活mod_rewrite!

10-06 04:32
查看更多