11/*
2- Copyright (c) 2013 Arduino LLC. All right reserved.
2+ Copyright (c) 2013-2014 Arduino LLC. All right reserved.
33
44 This library is free software; you can redistribute it and/or
55 modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,7 @@ unsigned int HttpClient::get(String &url) {
2828 if (insecure) {
2929 addParameter (" -k" );
3030 }
31+ addHeader ();
3132 addParameter (url);
3233 return run ();
3334}
@@ -37,6 +38,7 @@ unsigned int HttpClient::get(const char *url) {
3738 if (insecure) {
3839 addParameter (" -k" );
3940 }
41+ addHeader ();
4042 addParameter (url);
4143 return run ();
4244}
@@ -46,6 +48,7 @@ void HttpClient::getAsynchronously(String &url) {
4648 if (insecure) {
4749 addParameter (" -k" );
4850 }
51+ addHeader ();
4952 addParameter (url);
5053 runAsynchronously ();
5154}
@@ -55,6 +58,43 @@ void HttpClient::getAsynchronously(const char *url) {
5558 if (insecure) {
5659 addParameter (" -k" );
5760 }
61+ addHeader ();
62+ addParameter (url);
63+ runAsynchronously ();
64+ }
65+
66+ unsigned int HttpClient::post (String &url, String &data) {
67+ return post (url.c_str (), data.c_str ());
68+ }
69+
70+ unsigned int HttpClient::post (const char *url, const char *data) {
71+ begin (" curl" );
72+ if (insecure) {
73+ addParameter (" -k" );
74+ }
75+ addParameter (" --request" );
76+ addParameter (" POST" );
77+ addParameter (" --data" );
78+ addParameter (data);
79+ addHeader ();
80+ addParameter (url);
81+ return run ();
82+ }
83+
84+ void HttpClient::postAsynchronously (String &url, String &data) {
85+ postAsynchronously (url.c_str (), data.c_str ());
86+ }
87+
88+ void HttpClient::postAsynchronously (const char *url, const char *data) {
89+ begin (" curl" );
90+ if (insecure) {
91+ addParameter (" -k" );
92+ }
93+ addParameter (" --request" );
94+ addParameter (" POST" );
95+ addParameter (" --data" );
96+ addParameter (data);
97+ addHeader ();
5898 addParameter (url);
5999 runAsynchronously ();
60100}
@@ -75,3 +115,18 @@ void HttpClient::checkSSL() {
75115 insecure = false ;
76116}
77117
118+ void HttpClient::setHeader (String &header) {
119+ this ->header = header;
120+ }
121+
122+ void HttpClient::setHeader (const char * header) {
123+ this ->header = String (header);
124+ }
125+
126+ void HttpClient::addHeader () {
127+ if (header.length () > 0 ) {
128+ addParameter (" --header" );
129+ addParameter (header);
130+ }
131+ }
132+
0 commit comments