curl_easy_perform() 失败:SSL 对等证书或 SSH 远程密钥不正确
curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK
运行 此代码出现错误 "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 验证。
我发现您需要在此处下载 .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");
运行 此代码出现错误 "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 验证。
我发现您需要在此处下载 .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");