I am trying to execute some request through the curl library from C ++. I can successfully execute my request and get the correct answer through the command line but I can't get the correct answer through C ++ code . My command line command looks like this:
curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: <some_hash_value>' -k <my_full_url> -data '<my_json_string>'
It works great. Now I am trying to execute the same request in C ++ code. My code is as follows:
void performRequest(const std::string& json, const void* userData, CallbackFunction callback) { struct curl_slist* headers = NULL; headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, (std::string("Authorization: ") + m_authorization).c_str()); CURL* curlHandle = curl_easy_init(); if (!curlHandle) { std::cerr << "Curl handler initialization failed"; } curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, headers);
However, for some reason, I get an error in the response from the server, from which I can assume that my code request is not equivalent to the command line command. It seems that the body is not sent. I cannot see my Json body request when I use CURLOPT_DEBUGFUNCTION to reset debug information.
What is the problem? What am I doing wrong? Any ideas?
c ++ json c curl libcurl
nabroyan
source share