c++ - 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 验证。
解决方案
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");
推荐阅读
- python - 为什么我不能使用 python 在我的树莓派中创建杯子连接?
- java - 是否可以使用键和分区来消费 kafka 消息?
- laravel - 如何检查它返回的响应代码是否为“421”?
- javascript - 如何在 chrome 扩展中获取响应 JSON
- python - 如何使用递归在 BeautifulSoup 中进行抓取?
- c# - NEST 如何在子文档中查找字段
- python - 在 Wagtail 中使用 InlinePanel 创建模型实例
- axapta - TmpTaxWorkTrans 表中的 SourceBaseAmountCur 字段是如何计算的?
- python - 为什么编辑网格单元后会出现错误?
- flutter - Flutter 中的主屏幕小部件