hs4yeq
Last Updated: February 25, 2016
·
1.04K
· cristiansitov

Guzzle 5.* request on HTTPS with self-signed certs

Usually, Guzzle was built to work "oob", without hassle and only with a few lines of code. If Guzzle is mounted in autoload, then it should look like this:

$client   = new GuzzleHttp\Client();
$response = $client->get("http://localhost/");

Ok. Nice! Everything looks clean, right?

However, when doing a HTTPS request and self-signed certs are installed on your server, you will have to add an extra CURLOPT so that it will pass checking the certification check, and domain check.

For this, you'll have to pass an array with configuration params to the get() method.

$client   = new GuzzleHttp\Client();
$response = $client->get(
    "http://localhost/", [
        'config' => [
            'curl' => [
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_SSL_VERIFYHOST => false
            ]
        ]
    ]);

Have fun! ;)