每当我尝试使用 guzzle 请求 localhost:8000/any 时,Laravel 服务器就会挂起

Car*_*Ihl 7 php localhost laravel guzzle

如果我提出任何请求http://localhost:8000http://127.0.0.1:8000它挂在状态挂起。(正如这里https://github.com/guzzle/guzzle/issues/1857

有人告诉我这与暴饮暴食无关,我最好在这里问一下。

我在关注 laravel.com/docs/5.4/passport 时偶然发现了这个问题

这是挂起的代码:

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'authorization_code',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'redirect_uri' => 'http://example.com/callback',
        'code' => $request->code,
    ],
]);
Run Code Online (Sandbox Code Playgroud)

我尝试向工作 API 路由发出 GET 和 POST 请求(用邮递员测试),但在使用 guzzle 调用相同路由时它仍然挂起。

那么有没有办法在使用时向我自己的 API 发出请求php artisan serve

bus*_*ing 7

卡尔对此有一个很好的解决方案。如果您正在寻找快速修复来测试更新 - 您可以通过打开两个命令提示符来完成此操作。第一个将运行php artisan serve(本地我的默认端口是 8000,您将在 上运行您的站点http://localhost:8000)。第二个会运行php artisan serve --port 8001

然后您将您的帖子请求更新为:

$response = $http->post('http://localhost:8001/oauth/token', [
    'form_params' => [
        'grant_type' => 'authorization_code',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'redirect_uri' => 'http://example.com/callback',
        'code' => $request->code,
    ],
]);
Run Code Online (Sandbox Code Playgroud)

这应该在您的测试过程中有所帮助,直到您能够访问服务器或本地虚拟主机上的所有内容。