Lumen API与OAuth,Guzzle获取/发布方法


Lumen API with OAuth, Guzzle get/post method

我正在构建一个使用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/hello上localhost:8000''api的请求不起作用,但来自localhost:800/api上的GET请求http://www.google.com/做
示例:

$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''.htacccess带有

<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!