【问题标题】:When I use GuzzleHttp on localhost hang up my Laravel app当我在 localhost 上使用 GuzzleHttp 时,挂断我的 Laravel 应用程序
【发布时间】:2018-12-15 14:24:10
【问题描述】:

当我使用GuzzleHttp 并发送请求时,我的laravel 程序被中断,我将停止服务器并再次运行它。如果使用在线 API 或仅使用没有端口号的 localhost,则没有问题并且可以正常工作。但是当使用端口 8000 或任何端口时,Laravel 应用程序会挂断。

我的代码是

$http = new \GuzzleHttp\Client;
$response = $http->post('http://localhost:8000/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 2,
        'client_secret' => 'AXXwkDGiuEewwd1tza4haWrz6Gku0LRGgLIaayxC',
        'username' => 'saeed',
        'password' => '12345678',
    ]
]);
return json_decode((string)$response->getBody(), true);

【问题讨论】:

    标签: php laravel curl guzzle


    【解决方案1】:

    尝试按照此处所述设置显式端口:http://docs.guzzlephp.org/en/5.3/http-messages.html#port

    $request->setPort(8000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-31
      • 2018-12-09
      • 2019-10-12
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多