I have this code:
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_URL, "localhost/rest-v1/devices/did1/tasks");
curl_easy_setopt(curl,CURLOPT_PORT,22080);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"hello\" : \"darkness\"}");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
}
When I run it I get this print on console:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 22080 (#0)
> POST /rest-v1/devices/did1/tasks HTTP/1.1
Host: localhost:22080
Accept: */*
Content-Length: 16
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 16 out of 16 bytes
< HTTP/1.1 415 Unsupported Media Type
< Server: Restlet-Framework/2.3.9
< Date: Fri, 23 Jun 2017 06:44:09 GMT
< Content-type: application/json; charset=UTF-8
< Content-language: *
< Content-length: 35
< Accept-ranges: bytes
<
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
So it returns 415 Unsupported Media Type error code.
I found on StackOverflow that it may be caused by charset=UTF-8 in Context-type. So my question is, how can I edit this field to meet my needs (remove charset=UTF-8). link
How to change that Content-type. Since I'm new to HTTP protocol, please elaborate.