简体   繁体   中英

SSL certificate issue C

I'm trying to send https requests (ssl) to an API server (Last.fm) with libcurl. When i try to send http requests it's OK but when i send https requests it isn't. After many searches in google and stack overflow i get this sample code from internet and try to execute it but it doesn't work and show this error :

curl_easy_perform() failed: Peer certificate cannot be authenticated with given CA certificates

there is the sample code :

#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: I'm compiling with gcc from my terminal.

I fixed the problem by removing libcurl4-gnutls-dev and installing libcurl4-openssl-dev. If you have the same problem you just need this command :

sudo apt-get install libcurl4-openssl-dev

This removed libcurl4-gnutls-dev automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM