2017-04-11 175 views
0

我正在尝试使用libcurl将https请求(ssl)发送到API服务器(Last.fm)。当我尝试发送http请求它没关系,但是当我发送https请求它不是。在谷歌和堆栈溢出很多搜索后我从上网本示例代码和尝试执行它,但它不能正常工作,并显示此错误:SSL证书问题C

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; 

} 

PS:我是从我的终端GCC编译。

回答

0

我通过删除libcurl4-gnutls-dev和安装libcurl4-openssl-dev来解决了这个问题。如果你有同样的问题,你只需要这个命令:

sudo apt-get install libcurl4-openssl-dev 

这将自动删除libcurl4-gnutls-dev。