cURL requires CURLOPT_SSL_VERIFYPEER=FALSE

前端 未结 3 1697
温柔的废话
温柔的废话 2020-12-01 08:04

I was using cURL on my localhost for the longest time and all the sudden I noticed it no longer works unless I explictly set the option, CURLOPT_SSL_VERIFYPEER=

相关标签:
3条回答
  • 2020-12-01 08:39

    The value for CURLOPT_SSL_VERIFYPEER by default is TRUE as of cURL 7.10.

    Hence you may need to explicitly set it to FALSE to prevent CURL from verifying the certificate.

    0 讨论(0)
  • 2020-12-01 08:45

    Thanks to Dave Chen's suggestions, I realized I must have misplaced my certificate. The problem is solved by this certificate which is provided by the cURL creator (extracted from Mozilla): https://curl.haxx.se/ca/cacert.pem

    So after downloading this cacert.pem file into your project, in PHP you can now do this:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
    curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");
    

    Alternatively, this can be set globally by adding the following to your php.ini

    curl.cainfo=/path/to/cacert.pem
    
    0 讨论(0)
  • 2020-12-01 08:51

    If you are using WampServer, notice this:

    You must put the absolute path in CURLOPT_CAINFO, for example:

    curl_setopt ($ch, CURLOPT_CAINFO, 'C:\wamp\www\your-project\cacert.pem')
    

    Don't use relative path: curl_setopt ($ch, CURLOPT_CAINFO, 'cacert.pem') because it doesn’t work.

    0 讨论(0)
提交回复
热议问题