This is my code:
Vibranium::BBManager::HttpGetUserGamesRequest(const std::string& access_token)
{
auto available_games = std::make_unique<std::vector<int32>>();
std::string const auth_get_user_games_request_url = sConfigMgr->GetStringDefault("AuthAPIGetUserGamesUrl", "");
std::string const auth_bearer_request = "Authorization: Bearer " + access_token;
Document document_request(rapidjson::kObjectType);
StringBuffer request_buffer;
Writer<StringBuffer> writer(request_buffer);
document_request.Accept(writer);
// send cURL request
curl_global_init(CURL_GLOBAL_ALL);
std::string readBuffer;
CURL *curl = curl_easy_init();
if (curl)
{
struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, auth_bearer_request.c_str());
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, auth_get_user_games_request_url.c_str());
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_buffer.GetString());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Request::WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
auto curl_code = curl_easy_perform(curl);
auto http_code = 0;
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code != 200 || curl_code != CURLE_OK)
{
LOG_ERROR("Curl failed with HTTP code {} , and curl code {}", http_code, curl_code);
return available_games;
}
curl_easy_cleanup(curl);
}
else
{
LOG_ERROR("cURL_easy initialization error!");
return available_games;
}
// parse JSON response
rapidjson::Document parsed_response;
parsed_response.Parse(readBuffer.c_str());
if (!parsed_response.IsArray())
{
LOG_ERROR("No available data for user games!");
return available_games;
}
// Iterate through the array and access "id" values
for (rapidjson::SizeType i = 0; i < parsed_response.Size(); ++i)
{
if (parsed_response[i].HasMember("id") && parsed_response[i]["id"].IsInt())
{
auto id = parsed_response[i]["id"].GetInt();
available_games->push_back(id);
}
}
return available_games;
}
This code works in Debug mode and fetches the response from the https website. However in Release mode it does not and returns curl error code 77.
Any idea what is that difference between Debug and Release and how can I fix it ?