How to ignore invalid SSL certificate errors in Gu

2020-02-24 05:45发布

This should be an easy thing to do. I can find plenty of references to how to do it in Guzzle 3, but they don't work in Guzzle 5.

What I am doing so far:

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

When I send a request though I get this error:

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

I cannot find any useful reference to this error on google. If I could get access to the curl options then I could try something like the solution suggested here (which is for Guzzle 3, hence why it doesn't work): http://inchoo.net/dev-talk/symfony2-guzzle-ssl-self-signed-certificate/, the relevant section of which is:

$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);

3条回答
The star\"
2楼-- · 2020-02-24 06:18

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
]]);
查看更多
ゆ 、 Hurt°
3楼-- · 2020-02-24 06:24

You should use

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

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

The documentation is here: http://guzzle.readthedocs.org/en/latest/clients.html#verify

查看更多
叛逆
4楼-- · 2020-02-24 06:33

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.

查看更多
登录 后发表回答