【问题标题】:cURL error 6 in sending request with guzzle使用 guzzle 发送请求时出现 cURL 错误 6
【发布时间】:2020-08-03 03:40:18
【问题描述】:

在我的 laravel 应用程序中,我想用 guzzle 发送 http 请求。

这是我的代码:

$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
  'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();

这个结果:

cURL 错误 6:无法解析主机:api.github.com

我该如何解决这个问题?

【问题讨论】:

标签: laravel curl guzzle


【解决方案1】:

我相信您需要定义您的身份验证常量,

$client = new \GuzzleHttp\Client();
define("auth", \GuzzleHttp\RequestOptions::AUTH );
$res = $client->request('GET', 'https://api.github.com/user', [
  'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多