【问题标题】:cURL error 60: SSL certificate problem: self signed certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)cURL 错误 60:SSL 证书问题:自签名证书(参见 http://curl.haxx.se/libcurl/c/libcurl-errors.html)
【发布时间】:2019-12-17 08:19:15
【问题描述】:

我在我的 Laravel 5.8 项目中使用 Guzzle

我正在尝试在 https 上提供对 URL(签名证书)的 GET 服务

“https://172.1.1.1:443/accounts”

public static function get($url) {

    // dd($url);

    try {
        $client = new Client();
        $options = [
            'http_errors'     => true,
            'connect_timeout' => 3.14,
            'read_timeout'    => 3.14,
            'timeout'         => 3.14,
            'curl'            => array(
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false
            )

        ];

        $headers = [
            'headers' => [
                'Keep-Alive' => 'timeout=300'
            ]
        ];

        $result = $client->request('GET', $url, $headers, $options);


        // dd($result);



    } catch (ConnectException $e) {

        //Logging::error($e);

        return null;
    }

    return json_decode($result->getBody(), true);
}

我已经用过这两个标志了

CURLOPT_SSL_VERIFYHOST => false,
URLOPT_SSL_VERIFYPEER => false

我不知道为什么我一直得到,

【问题讨论】:

标签: php curl guzzle6 guzzle


【解决方案1】:

唯一合理的解释(缺少cosmic rays 和 ram 错误)是客户端(无论客户端是什么)要么覆盖您的自定义 curl 设置,要么忽略它们。禁用CURLOPT_SSL_VERIFYHOST 和CURLOPT_SSL_VERIFYPEER 应该没有办法解决该错误。

...顺便说一句,如果那是 Guzzle\Client,您是否尝试将 'verify' => 'false' 添加到 $options ?这应该是禁用它的 guzzle 方式,如果 Guzzle 覆盖您的自定义设置,因为 Guzzle 的 verify 选项没有被禁用(它是 enabled by default),我不会感到惊讶(enabled by default)

【讨论】:

    【解决方案2】:

    我同意@hanshenrik 的观点,我对其进行了测试,这正是问题所在。默认情况下,您创建的客户端具有以下配置:

    $defaults = [
                'allow_redirects' => RedirectMiddleware::$defaultSettings,
                'http_errors'     => true,
                'decode_content'  => true,
                'verify'          => true,
                'cookies'         => false
            ];
    

    所以你必须把它改成:

    public static function get($url) {
    
        // dd($url);
    
        try {
            $client = new Client(['verify' => false]);
            $options = [
                'http_errors'     => true,
                'connect_timeout' => 3.14,
                'read_timeout'    => 3.14,
                'timeout'         => 3.14
                )
            ];
    
            $headers = [
                'headers' => [
                    'Keep-Alive' => 'timeout=300'
                ]
            ];
    
            $result = $client->request('GET', $url, $headers, $options);
    
    
            // dd($result);
    
    
    
        } catch (ConnectException $e) {
    
            //Logging::error($e);
    
            return null;
        }
    
        return json_decode($result->getBody(), true);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 2016-04-14
      • 2020-07-02
      • 2021-01-08
      • 1970-01-01
      • 2019-05-25
      • 2016-12-18
      • 2020-09-20
      • 1970-01-01
      相关资源
      最近更新 更多