首页 > 解决方案 > curl_easy_perform() 失败:SSL 对等证书或 SSH 远程密钥不正确

问题描述

运行此代码我收到错误“curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK”

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL* curl;
    CURLcode res;

    curl = curl_easy_init();
    if (curl) {
        /* First set the URL that is about to receive our POST. This URL can
           just as well be a https:// URL if that is what should receive the
           data. */
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.quandl.com/api/v3/datasets/WIKI/FB/data.json?api_key=MY-CODE-HERE");
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
        {
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        }

        /* always cleanup */
        curl_easy_cleanup(curl);
    }
    return 0;
}

quandl 网站上有一个使用此确切 GET 请求的示例。虽然它正在使用 curl.exe,但我认为它与此无关。

quandl 网站上没有提到如何获取证书或密钥,所以我最初的想法是他们不允许直接使用 libcurl 或 curl.exe 从 quandl 服务器检索一些证书。

我也尝试了 google.com 并得到了同样的错误。

有人遇到过这个吗?

编辑

我不想绕过 SSL 验证。

标签: c++cssllibcurlquandl

解决方案


I found out you need to download the .pem file here https://curl.haxx.se/docs/caextract.html

And add these settings...

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1);            
curl_easy_setopt(curl, CURLOPT_CAINFO, "PATH TO FILE\\cacert.pem");
curl_easy_setopt(curl, CURLOPT_CAPATH, "PATH TO FILE\\cacert.pem");

推荐阅读