Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore invalid SSL certificate errors in Guzzle 5

Tags:

php

curl

ssl

guzzle

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); 
like image 542
Gnuffo1 Avatar asked Jan 21 '15 11:01

Gnuffo1


People also ask

How do I bypass a validation certificate?

To bypass SSL certificate validation for local and test servers, you can pass the -k or --insecure option to the Curl command. This option explicitly tells Curl to perform "insecure" SSL connections and file transfers. Curl will ignore any security warnings about an invalid SSL certificate and accept it as valid.

Why do I keep getting invalid certificate?

An SSL certificate error occurs when the browser cannot verify the SSL certificates returned by the server. When the error happens, the browser blocks the website and warns the user that the website cannot be trusted as shown below. These warnings will negatively impact the user's trust in your website.


2 Answers

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).

like image 123
pjcdawkins Avatar answered Sep 21 '22 11:09

pjcdawkins


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.

like image 31
SND Avatar answered Sep 20 '22 11:09

SND