curl_easy_perform() 失败:SSL 对等证书或 SSH 远程密钥不正常

curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK

本文关键字:SSH 程密钥 不正常 密钥 SSL perform easy 失败 对等 curl 证书      更新时间:2023-10-16

运行此代码时出现错误"curl_easy_perform(( 失败:SSL 对等证书或 SSH 远程密钥不正常">

#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: %sn", curl_easy_strerror(res));
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}

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

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

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

有人遇到过这个吗?

编辑

我不想绕过 SSL 验证。

我发现您需要在此处下载.pem文件 https://curl.haxx.se/docs/caextract.html

并添加这些设置...

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");