SSL证书发行C

SSL certificate issue C

我正在尝试使用 libcurl 将 https 请求 (ssl) 发送到 API 服务器 (Last.fm)。当我尝试发送 http 请求时没问题,但是当我发送 https 请求时却不行。在 google 和堆栈溢出中进行多次搜索后,我从互联网上获取了此示例代码并尝试执行它,但它不起作用并显示此错误:

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。