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.

0
Top

Enjoyed this post?

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

Author

Darko Goles

Mobile Team PHP Web developer

Darko is PHP – Web developer and web support, web services specialized team member of Inchoo's mobile team.

Other posts from this author

Discussion 0 Comments

Add Comment

Add Your Comment

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