1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-04-19 21:22:15 +03:00

Always finish headers if a request body is provided to startRequest

This commit is contained in:
Sandeep Mistry 2016-06-22 12:59:38 -04:00
parent f56eecbc6f
commit 8f42a68a50
2 changed files with 12 additions and 9 deletions

View File

@ -118,17 +118,19 @@ int HttpClient::startRequest(const char* aURLPath, const char* aHttpMethod,
sendHeader(HTTP_HEADER_CONTENT_LENGTH, aContentLength);
}
if ((initialState == eIdle))
bool hasBody = (aBody && aContentLength > 0);
if (initialState == eIdle || hasBody)
{
// This was a simple version of the API, so terminate the headers now
finishHeaders();
if (aBody && aContentLength > 0)
{
write(aBody, aContentLength);
}
}
// else we'll call it in endRequest or in the first call to print, etc.
if (hasBody)
{
write(aBody, aContentLength);
}
}
return ret;

View File

@ -75,7 +75,7 @@ public:
int post(const char* aURLPath);
int post(const String& aURLPath);
/** Connect to the server and start to send a POST request
/** Connect to the server and send a POST request
with body and content type
@param aURLPath Url to request
@param aContentType Content type of request body
@ -93,7 +93,7 @@ public:
int put(const char* aURLPath);
int put(const String& aURLPath);
/** Connect to the server and start to send a PUT request
/** Connect to the server and send a PUT request
with body and content type
@param aURLPath Url to request
@param aContentType Content type of request body
@ -111,7 +111,7 @@ public:
int del(const char* aURLPath);
int del(const String& aURLPath);
/** Connect to the server and start to send a DELETE request
/** Connect to the server and send a DELETE request
with body and content type
@param aURLPath Url to request
@param aContentType Content type of request body
@ -123,6 +123,7 @@ public:
int del(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);
/** Connect to the server and start to send the request.
If a body is provided, the entire request (including headers and body) will be sent
@param aURLPath Url to request
@param aHttpMethod Type of HTTP request to make, e.g. "GET", "POST", etc.
@param aContentType Content type of request body (optional)