php 如何修复Symfony/Goutte中的SSL问题

huwehgph  于 2023-04-10  发布在  PHP
关注(0)|答案(2)|浏览(167)

我试图向Symfony/Goutte的网站提出请求,但我收到这样的错误:

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".

代码如下:

use Goutte\Client;

$client = new Client();

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

如何解决这个问题?

ep6jt1vc

ep6jt1vc1#

您需要添加HttpClient并禁用SSL检查...(仅在调试时这样做)而不是在生产中!

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');
g6baxovj

g6baxovj2#

如果你在localhost中工作,你可以在config/packages/frameworks.yaml中禁用SSL check globally,并粘贴以下内容:

http_client:
    default_options:
        verify_host: false
        verify_peer: false

希望对你有帮助!

相关问题