Add method to measure the JSON length
Created by: max929292
I am using POST requests to send data to a webserver. These requests only work if we add the content length in the request. I do not want to use a char conversion via printTo as then I need to define the size of the char array which I would like to keep dynamic. I am directly pushing the json to my EthernetClient however I do not know if there is a simple way to pull the content length from it.
Would be great if you could give me some pointers.
EthernetClient client;
JsonObject& root = jsonBuffer.createObject();
....
client.println("POST /datapoints HTTP/1.1");
client.println("Host: xxx.xxx.xxx.xxx:3000");
client.println("User-Agent: Arduino/1.0");
client.println("Accept: application/json");
client.print("Content-Length: ");
client.println(root.length); //How can i get length of json? root.length() is not available
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
root.printTo(client);