I am not very familiar with curl or HTTP requests, but trying to learn.
In my case, I am trying to use libcurl in C++ (using Visual Studio 2019 on Windows 10) to perform a GET
request. I tried solutions from Curl in C++ - Can't get data from HTTPS, but the only thing that worked for me was to disable SSL peer verification using:
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
Here is my code:
void getPairPrice(string & pair) {
string url(BINANCE_HOST);
url += "/api/v3/ticker/price?symbol=";
url += pair;
CURL* curl;
CURLcode res;
std::string readBuffer;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, PUBLIC_KEY_HEADER);
headers = curl_slist_append(headers, CONTENT_TYPE_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
//cout << "res : " << res << endl;
std::cout << "GET symbol " << pair << " price : " << readBuffer << std::endl;
const string jsonKey = "price";
cout << "Price : " << extractJsonValue(readBuffer, jsonKey) << endl;
}
curl_easy_cleanup(curl);
curl_global_cleanup();
}
Without disabling the SSL_VERIFYPEER
option, the response is always 77. This is fine for testing, but I would like to know how to solve that when releasing my software. It seems that I should somehow download the host's SSL certificate in PEM format and point libcurl to it.
Can anyone help?