我正在尝试使用 libcurl 将 https 请求 (ssl) 发送到 API 服务器 (Last.fm)。当我尝试发送 http 请求时没问题,但是当我发送 https 请求时却不行。在谷歌和堆栈溢出中进行多次搜索后,我从互联网上获得了这个示例代码并尝试执行它但它不起作用并显示此错误:
curl_easy_perform() failed: Peer certificate cannot be authenticated with given CA certificates
有示例代码:
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
int main() {
CURLcode res;
CURL *handle = curl_easy_init();
char url[] = "https://google.com";
curl_easy_setopt(handle, CURLOPT_URL, url);
res=curl_easy_perform(handle);
if(res==CURLE_OK)
{
printf("OK");
}
else{
printf("curl_easy_perform() failed: %s \n", curl_easy_strerror(res));
}
return 0;
}
P.S:我正在从我的终端使用 gcc 进行编译。
最佳答案
我通过删除 libcurl4-gnutls-dev 并安装 libcurl4-openssl-dev 解决了这个问题。如果你有同样的问题,你只需要这个命令:
sudo apt-get install libcurl4-openssl-dev
这会自动删除 libcurl4-gnutls-dev。
关于c - SSL证书问题C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43350964/