Skip to content

POST request without content-length possible? #358

@FrederikWolter

Description

@FrederikWolter

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions