1
1
/*
2
- Copyright (c) 2013 Arduino LLC. All right reserved.
2
+ Copyright (c) 2013-2014 Arduino LLC. All right reserved.
3
3
4
4
This library is free software; you can redistribute it and/or
5
5
modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,7 @@ unsigned int HttpClient::get(String &url) {
28
28
if (insecure) {
29
29
addParameter (" -k" );
30
30
}
31
+ addHeader ();
31
32
addParameter (url);
32
33
return run ();
33
34
}
@@ -37,6 +38,7 @@ unsigned int HttpClient::get(const char *url) {
37
38
if (insecure) {
38
39
addParameter (" -k" );
39
40
}
41
+ addHeader ();
40
42
addParameter (url);
41
43
return run ();
42
44
}
@@ -46,6 +48,7 @@ void HttpClient::getAsynchronously(String &url) {
46
48
if (insecure) {
47
49
addParameter (" -k" );
48
50
}
51
+ addHeader ();
49
52
addParameter (url);
50
53
runAsynchronously ();
51
54
}
@@ -55,6 +58,43 @@ void HttpClient::getAsynchronously(const char *url) {
55
58
if (insecure) {
56
59
addParameter (" -k" );
57
60
}
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 ();
58
98
addParameter (url);
59
99
runAsynchronously ();
60
100
}
@@ -75,3 +115,18 @@ void HttpClient::checkSSL() {
75
115
insecure = false ;
76
116
}
77
117
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