Symfony2 – Guzzle using with SSL self-signed certificate

Featured Image

CDWaldi@sxc.hu

In previous post I explained to install and setup Guzzle Php web client library with help of GuzzleBundle for Symfony2.

Now I am going to explain how to use it with SSL self-signed certificate.

It’s pretty easy to implement, since Guzzle web client library is built on top of cURL and have options to set manually needed cURL parameters as we need to.

Let’s make some sample GET request to some ‘https://’

//somecontroller.php
//...
$client = new \Guzzle\Service\Client();
$req = $client->get('https://someurl.com/with_self_signed_certificate');
$response = $req->send();
print_r($response);exit;
//...

It will not be enough yet …
Let’s add two more lines to make it work:

//somecontroller.php
//...
$client = new \Guzzle\Service\Client();
$req = $client->get('https://someurl.com/with_self_signed_certificate');
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$req->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
$response = $req->send();
print_r($response);exit;
//...

And that’s it.
Of course, you can set any cURL option that is available and about that you can read here [http://php.net/manual/en/function.curl-setopt.php]

Cheers.

2
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Darko Goles

Magento backend developer

Other posts from this author

Discussion 2 Comments

Add Comment
  1. Thanks for the post. I do think the title is misleading, the post had nothing to do with certificates apart from how to bypass them.

    Maybe it should have been ‘How to set custom curl opts with Guzzle and Symfony’.

    Properly using self signed certificates using curl will involve setting CURLOPT_CAINFO, CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST. None of them should be false ;-) .

  2. @Richard, nice to see that somebody still reading old posts. Thanks for comment :-)

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top