From 8f6e0dd339114b05414ac35631b5f1254fd8b9c0 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 23 Nov 2019 21:53:29 -0700 Subject: [PATCH] Allow for POSTs larger than a few 100 bytes (#6800) This is all @dirkx , whose PR unfortunately got borked when we were trying to update it to the new format. As @dirkx said: When sending POST responses of well over a K - _write() may not sent it all. Make sure we do -- but cap the individual writes - as somehow large 2-3k blobs seem to cause instability (on my 12F units). Supercedes #2528 --- .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 99080ef42..183c51616 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -677,9 +677,20 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s } // send Payload if needed - if(payload && size > 0) { - if(_client->write(&payload[0], size) != size) { - return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); + if (payload && size > 0) { + size_t byteswritten = 0; + const uint8_t *p = payload; + while (byteswritten < size) { + int written; + int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE); + written = _client->write(p, towrite); + if (written < 0) { + return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); + } else if (written == 0) { + return returnError(HTTPC_ERROR_CONNECTION_LOST); + } + byteswritten += written; + size -= written; } }