I\'m defining a PUT request with a JSON request body using libcurl in C.
This how I\'m doing it:
sprintf(jsonObj, \"\\\"name\\\" : \\\"%s\\\", \\
Had this same problem when posting data to node-red with json parser.
Solution for me was to treat string as a HTML
#include
int main (int argc, char *argv[]) {
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl == NULL) {
return 128;
}
struct curl_slist *headers = NULL;
curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, #yourURL);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "age=42&sex=male");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
Hope someone will find it helpful.