【发布时间】:2017-09-07 03:18:44
【问题描述】:
我正在尝试使用 libcurl 将 https 请求 (ssl) 发送到 API 服务器 (Last.fm)。当我尝试发送 http 请求时它可以,但是当我发送 https 请求时它不是。在谷歌和堆栈溢出多次搜索后,我从互联网上获取了这个示例代码并尝试执行它,但它不起作用并显示此错误:
curl_easy_perform() 失败:对等证书无法使用给定的 CA 证书进行身份验证
有示例代码:
#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 进行编译。
【问题讨论】:
标签: c ssl curl openssl ssl-certificate