Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request without content-length possible? #358

Open
FrederikWolter opened this issue Jul 20, 2020 · 0 comments
Open

POST request without content-length possible? #358

FrederikWolter opened this issue Jul 20, 2020 · 0 comments

Comments

@FrederikWolter
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant