我正在构建一个带有 OAuth2 身份验证的 Lumen API,我遵循了本教程:http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/但我收到一个错误:
“ fatal error :第 99 行 C:\Users\user\Desktop\api\lumen\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php 中超过 60 秒的最大执行时间”
< br/>
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 上不起作用,但是来自 localhost:8000/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\.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 !
关于php - 带有 OAuth 的 Lumen API,Guzzle get/post 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117856/