Parse Exception from a simple POST request

I am using sockets in C++ to communicate with Elasticsearch. I can communicate with my ELK instance (it is running in a docker compose, the docker files are here).

Here is the request that I am sending:

POST /twitter/_doc/1? HTTP/1.1
Content-Type: application/json; charset=UTF-8
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
'{ "post_date" : "2017-11-16T14:12:12", "message" : "trying out Elasticsearch FROM CPPPPP" }'
Connection: close

And here is the response that I am getting from the server:

HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
content-length: 163

{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}

I can confirm that I am sending and receiving this data by counting the bytes being sent and received.

I am confused because when I put that request into the Kibana console, it runs fine.

Any ideas on what would be wrong with the request that I am sending?

Here is the C++ code where I create the request:

	std::string post_http = "";
	post_http += "POST /twitter/_doc/1? HTTP/1.1\n";
	post_http += "Content-Type: application/json; charset=UTF-8\n";
	post_http += "Host: ";
	post_http += aURL;
	post_http += ":9200\n";
	post_http += "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36\n";
	post_http += "'{ \"post_date\" : \"2017-11-16T14:12:12\", ";
	post_http += "\"message\" : \"trying out Elasticsearch FROM CPPPPP\" }'";
	post_http += "\r\nConnection: close\r\n\r\n";

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.