How can I fix the SSL problem in Symfony/Goutte
Asked Answered
C

2

6

I'm trying to make a request to the website with Symfony/Goutte but I'm receiving such error:

In ErrorChunk.php line 65:
                                                                                                         
  SSL peer certificate or SSH remote key was not OK for "https://example.com".  
                                                                                                         
In CurlResponse.php line 298:
                                                                                                         
  SSL peer certificate or SSH remote key was not OK for "https://example.com".

Here's the code:

use Goutte\Client;

$client = new Client();

$client->request('GET', 'https://example.com');

How to fix this?

Coalfish answered 22/8, 2020 at 17:52 Comment(0)
K
17

You need to add HttpClient and disable SSL check... (do this only for debug) not in production!

use Goutte\Client;
use Symfony\Component\HttpClient\HttpClient;

$client = new Client(HttpClient::create(['verify_peer' => false, 'verify_host' => false]));
$client->request('GET', 'https://example.com');
Kronstadt answered 22/8, 2020 at 17:57 Comment(3)
But there's no setClient method in Goutte\ClientCoalfish
Changed to HttpClient for newer versions of Symfony.Kronstadt
If dependency injection is used, one can use $this->client = $client->withOptions(). symfony.com/doc/current/http_client.html#configurationNormalcy
T
2

If you work in localhost, you can disable SSL check globaly into config/packages/frameworks.yaml and paste this :

http_client:
    default_options:
        verify_host: false
        verify_peer: false

Hope that's help you !

Tahr answered 7/4, 2023 at 16:5 Comment(1)
Seems like it's config/packages/framework.yaml now. symfony.com/doc/current/http_client.html#configurationNormalcy

© 2022 - 2024 — McMap. All rights reserved.