openSenseMap icon indicating copy to clipboard operation
openSenseMap copied to clipboard

POST request without content-length possible?

Open FrederikWolter opened this issue 5 years ago • 0 comments

Hi, I am trying to optimize my code running on an ESP8266, which uploads the measurements of a BME280. A ineffective section, I think, is the calculation of "Content-Length", so I want to change it.

client.print(F("POST /boxes/")); printHexToStream(SENSEBOX_ID, 12, client); client.println(F("/data HTTP/1.1"));

// print once to Serial to get the content-length int contentLen = printCsvToStream(Serial);

// Send the required header parameters client.print(F("Host: ")); client.println(server); client.println(F("Content-Type: text/csv\nConnection: close")); client.print(F("Content-Length: ")); client.println(contentLen); client.println(); printCsvToStream(client); client.println();

client.flush(); client.stop();`

Expected Behavior

I tried leaving the "Content-Length" header out with the manual POST-request tool Postman and it worked!

POST /boxes/5cc2cfb9facf70001ac953f6/data HTTP/1.1 Host: ingress.opensensemap.org Content-Type: text/csv Connection: close Cache-Control: no-cache Postman-Token: 50a6222f-181e-ead7-4cba-a79b9aeaef95

5cc2cfb9facf70001ac953fb,28.87 5cc2cfb9facf70001ac953fa,43.66 5cc2cfb9facf70001ac953f9,1006.28

Actual Behavior

But using the ESP the measurements don´t update.

What is my mistake? Is it not possible to leave the length out? How can I optimize this instead?

FrederikWolter avatar Jul 20 '20 15:07 FrederikWolter