From 1453ab150cac32bfc652b8671dce97fc7c32caa7 Mon Sep 17 00:00:00 2001 From: aesapronov Date: Fri, 2 Feb 2018 17:59:20 +0300 Subject: [PATCH 1/2] Added possibility of sending POST with empty payload Specification does not prohibit the sending of an empty POST requests. In this case "Content-Length: 0" should be set. See thread here: http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index ad8b14892d..fe7286db23 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -396,6 +396,9 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) if(payload && size > 0) { addHeader(F("Content-Length"), String(size)); } + else { + addHeader(F("Content-Length"), "0"); + } // send Header if(!sendHeader(type)) { From 076a50bb0713721412fe7f4a2c262682937d3cf1 Mon Sep 17 00:00:00 2001 From: aesapronov Date: Mon, 5 Feb 2018 19:19:59 +0300 Subject: [PATCH 2/2] Since Content-Length should always be exist, it has been rewrite to "one line" Allow to send POST with empty payload --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index fe7286db23..978e47593f 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -393,12 +393,7 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) return returnError(HTTPC_ERROR_CONNECTION_REFUSED); } - if(payload && size > 0) { - addHeader(F("Content-Length"), String(size)); - } - else { - addHeader(F("Content-Length"), "0"); - } + addHeader(F("Content-Length"), String(payload && size > 0 ? size : 0)); // send Header if(!sendHeader(type)) {