diff --git a/libraries/Bridge/src/HttpClient.cpp b/libraries/Bridge/src/HttpClient.cpp index 510af38d1c5..b263162b99f 100644 --- a/libraries/Bridge/src/HttpClient.cpp +++ b/libraries/Bridge/src/HttpClient.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013 Arduino LLC. All right reserved. + Copyright (c) 2013-2014 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,28 +20,62 @@ unsigned int HttpClient::get(String &url) { begin("curl"); + addHeader(); addParameter(url); return run(); } unsigned int HttpClient::get(const char *url) { begin("curl"); + addHeader(); addParameter(url); return run(); } void HttpClient::getAsynchronously(String &url) { begin("curl"); + addHeader(); addParameter(url); runAsynchronously(); } void HttpClient::getAsynchronously(const char *url) { begin("curl"); + addHeader(); addParameter(url); runAsynchronously(); } +unsigned int HttpClient::post(String &url, String &data) { + return post(url.c_str(), data.c_str()); +} + +unsigned int HttpClient::post(const char *url, const char *data) { + begin("curl"); + addParameter("--request"); + addParameter("POST"); + addParameter("--data"); + addParameter(data); + addHeader(); + addParameter(url); + return run(); +} + +void HttpClient::postAsynchronously(String &url, String &data) { + postAsynchronously(url.c_str(), data.c_str()); +} + +void HttpClient::postAsynchronously(const char *url, const char *data) { + begin("curl"); + addParameter("--request"); + addParameter("POST"); + addParameter("--data"); + addParameter(data); + addHeader(); + addParameter(url); + runAsynchronously(); +} + boolean HttpClient::ready() { return running(); } @@ -50,4 +84,18 @@ unsigned int HttpClient::getResult() { return exitValue(); } +void HttpClient::setHeader(String &header) { + this->header = header; +} + +void HttpClient::setHeader(const char * header) { + this->header = String(header); +} + +void HttpClient::addHeader() { + if (header.length() > 0) { + addParameter("--header"); + addParameter(header); + } +} diff --git a/libraries/Bridge/src/HttpClient.h b/libraries/Bridge/src/HttpClient.h index 00b6f9e5524..d1b815e7a52 100644 --- a/libraries/Bridge/src/HttpClient.h +++ b/libraries/Bridge/src/HttpClient.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013 Arduino LLC. All right reserved. + Copyright (c) 2013-2014 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -28,9 +28,18 @@ class HttpClient : public Process { unsigned int get(const char * url); void getAsynchronously(String &url); void getAsynchronously(const char * url); + unsigned int post(String &url, String &data); + unsigned int post(const char * url, const char * data); + void postAsynchronously(String &url, String &data); + void postAsynchronously(const char * url, const char * data); + void setHeader(String &header); + void setHeader(const char * header); boolean ready(); unsigned int getResult(); + private: + void addHeader(); + String header; }; #endif /* HTTPCLIENT_H_ */