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! ;)
Written by Cristian Sitov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Https
Authors
Related Tags
#https
#guzzle
#ringphp
#curlopt_ssl_verifypeer
#curlopt_ssl_verifyhost
#self signed certificates
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#