Skip to content

Commit 2f9bfda

Browse files
committed
allow HTTPClient to handle piece-wise sending of large payloads, in case the client (such as WifiClientSecure) does not
1 parent c93bf11 commit 2f9bfda

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,13 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
618618
}
619619

620620
// send Payload if needed
621-
if(payload && size > 0) {
622-
if(_client->write(&payload[0], size) != size) {
621+
if(payload && (size > 0)) {
622+
size_t totalSent = 0;
623+
while(_client->connected() && (totalSent < size))
624+
{
625+
totalSent += _client->write(&payload[totalSent], (size - totalSent));
626+
}
627+
if(totalSent != size) {
623628
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
624629
}
625630
}

0 commit comments

Comments
 (0)