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

Add new del API for HTTP DELETE method

This commit is contained in:
Sandeep Mistry 2016-06-22 12:16:12 -04:00
parent c3023b25ee
commit bdc5281733
3 changed files with 45 additions and 6 deletions

View File

@ -327,6 +327,31 @@ int HttpClient::put(const char* aURLPath, const char* aContentType, int aContent
return startRequest(aURLPath, HTTP_METHOD_PUT, aContentType, aContentLength, aBody); return startRequest(aURLPath, HTTP_METHOD_PUT, aContentType, aContentLength, aBody);
} }
int HttpClient::del(const char* aURLPath)
{
return startRequest(aURLPath, HTTP_METHOD_DELETE);
}
int HttpClient::del(const String& aURLPath)
{
return del(aURLPath.c_str());
}
int HttpClient::del(const char* aURLPath, const char* aContentType, const char* aBody)
{
return del(aURLPath, aContentType, strlen(aBody), (const byte*)aBody);
}
int HttpClient::del(const String& aURLPath, const String& aContentType, const String& aBody)
{
return del(aURLPath.c_str(), aContentType.c_str(), aBody.length(), (const byte*)aBody.c_str());
}
int HttpClient::del(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[])
{
return startRequest(aURLPath, HTTP_METHOD_DELETE, aContentType, aContentLength, aBody);
}
int HttpClient::responseStatusCode() int HttpClient::responseStatusCode()
{ {
if (iState < eRequestSent) if (iState < eRequestSent)

View File

@ -104,6 +104,24 @@ public:
int put(const String& aURLPath, const String& aContentType, const String& aBody); int put(const String& aURLPath, const String& aContentType, const String& aBody);
int put(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]); int put(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);
/** Connect to the server and start to send a DELETE request.
@param aURLPath Url to request
@return 0 if successful, else error
*/
int del(const char* aURLPath);
int del(const String& aURLPath);
/** Connect to the server and start to send a DELETE request
with body and content type
@param aURLPath Url to request
@param aContentType Content type of request body
@param aBody Body of the request
@return 0 if successful, else error
*/
int del(const char* aURLPath, const char* aContentType, const char* aBody);
int del(const String& aURLPath, const String& aContentType, const String& aBody);
int del(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);
/** Connect to the server and start to send the request. /** Connect to the server and start to send the request.
@param aURLPath Url to request @param aURLPath Url to request
@param aHttpMethod Type of HTTP request to make, e.g. "GET", "POST", etc. @param aHttpMethod Type of HTTP request to make, e.g. "GET", "POST", etc.

View File

@ -50,14 +50,10 @@ void setup() {
void loop() { void loop() {
Serial.println("making DELETE request"); Serial.println("making DELETE request");
String contentType = "application/x-www-form-urlencoded";
String delData = "name=light&age=46"; String delData = "name=light&age=46";
client.beginRequest(); client.del("/", contentType, delData);
client.startRequest("/", HTTP_METHOD_DELETE);
client.sendHeader("Content-Type", "application/x-www-form-urlencoded");
client.sendHeader("Content-Length", delData.length());
client.endRequest();
client.write((const byte*)delData.c_str(), delData.length());
// read the status code and content length of the response // read the status code and content length of the response
statusCode = client.responseStatusCode(); statusCode = client.responseStatusCode();