如何忽略 Guzzle5中无效的 SSL 证书错误

这应该很简单。我可以找到很多关于如何在狂饮3中做到这一点的参考资料,但是它们在狂饮5中不起作用。

到目前为止我所做的:

$this->client = new GuzzleClient(['defaults' => [
'verify' => 'false'
]]);

当我发送一个请求时,我得到这个错误:

RequestException in RequestException.php line 51:
SSL CA bundle not found: false

我不能找到任何有用的参考在谷歌这个错误。如果我可以访问旋度选项,那么我可以尝试类似这里建议的解决方案(这是为狂饮3,因此它不工作) : http://inchoo.net/dev-talk/symfony2-guzzle-ssl-self-signed-certificate/,其中的相关部分是:

$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
129144 次浏览

You should use

$this->client = new GuzzleClient(['defaults' => [
'verify' => false
]]);

i.e. a Boolean false, not the string 'false'

The documentation is here: https://docs.guzzlephp.org/en/5.3/clients.html#verify

Note: a few people have given other answers that apply to Guzzle 6+. They're good answers if you are using those versions (but the original question was explicitly about Guzzle 5).

Try with updated version that works:

$this->client = new GuzzleClient(['base_uri' => 'https://api.example.com/', 'verify' => false ]);

or a more simple version:

    $this->client = new GuzzleClient(['verify' => false ]);

Tested with version 6.2-dev.

The actual version is the correct one:

$this->client = new GuzzleClient(['verify' => false ]);

At 2018, this does not work:

$this->client = new GuzzleClient(['defaults' => [
'verify' => false
]]);

you can use in the new laravel client version with

$http = new Client(['verify' => false]);