2017-04-11 170 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。