diff --git a/examples/PostWithHeaders/PostWithHeaders.ino b/examples/PostWithHeaders/PostWithHeaders.ino index b39afae..06139db 100644 --- a/examples/PostWithHeaders/PostWithHeaders.ino +++ b/examples/PostWithHeaders/PostWithHeaders.ino @@ -58,8 +58,9 @@ void loop() { client.sendHeader("Content-Type", "application/x-www-form-urlencoded"); client.sendHeader("Content-Length", postData.length()); client.sendHeader("X-Custom-Header", "custom-header-value"); - client.endRequest(); + client.beginBody(); client.print(postData); + client.endRequest(); // read the status code and body of the response statusCode = client.responseStatusCode(); diff --git a/keywords.txt b/keywords.txt index 7c2061c..1f4a10e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -20,6 +20,7 @@ put KEYWORD2 patch KEYWORD2 startRequest KEYWORD2 beginRequest KEYWORD2 +beginBody KEYWORD2 sendHeader KEYWORD2 sendBasicAuth KEYWORD2 endRequest KEYWORD2 diff --git a/src/HttpClient.cpp b/src/HttpClient.cpp index f3accc3..b46f628 100644 --- a/src/HttpClient.cpp +++ b/src/HttpClient.cpp @@ -263,6 +263,11 @@ void HttpClient::flushClientRx() } void HttpClient::endRequest() +{ + beginBody(); +} + +void HttpClient::beginBody() { if (iState < eRequestSent) { diff --git a/src/HttpClient.h b/src/HttpClient.h index eaab360..e627b21 100644 --- a/src/HttpClient.h +++ b/src/HttpClient.h @@ -62,6 +62,13 @@ public: */ void endRequest(); + /** Start the body of a more complex request. + Use this when you need to send the body after additional headers + in the request, but can optionally call endRequest() when + you are finished. + */ + void beginBody(); + /** Connect to the server and start to send a GET request. @param aURLPath Url to request @return 0 if successful, else error