File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
libraries/ESP8266httpClient/src Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 25
25
#include < Arduino.h>
26
26
#include < ESP8266WiFi.h>
27
27
#include < WiFiClientSecure.h>
28
+ #include < StreamString.h>
28
29
29
30
#include " ESP8266httpClient.h"
30
31
@@ -198,6 +199,7 @@ int httpClient::getSize(void) {
198
199
}
199
200
200
201
/* *
202
+ * deprecated Note: this is not working with https!
201
203
* returns the stram of the tcp connection
202
204
* @return WiFiClient
203
205
*/
@@ -211,6 +213,20 @@ WiFiClient & httpClient::getStream(void) {
211
213
// todo return error?
212
214
}
213
215
216
+ /* *
217
+ * returns the stram of the tcp connection
218
+ * @return WiFiClient *
219
+ */
220
+ WiFiClient * httpClient::getStreamPtr (void ) {
221
+ if (connected ()) {
222
+ return _tcp;
223
+ }
224
+
225
+ DEBUG_HTTPCLIENT (" [HTTP-Client] no stream to return!?\n " );
226
+ return NULL ;
227
+ }
228
+
229
+ WiFiClient * getStreamPtr (void );
214
230
/* *
215
231
* write all message body / payload to Stream
216
232
* @param stream Stream *
@@ -265,6 +281,25 @@ int httpClient::writeToStream(Stream * stream) {
265
281
return bytesWritten;
266
282
}
267
283
284
+ /* *
285
+ * return all payload as String (may need lot of ram or trigger out of memmory!)
286
+ * @return String
287
+ */
288
+ String httpClient::getString (void ) {
289
+ StreamString sstring;
290
+
291
+ if (_size) {
292
+ // try to reserve needed memmory
293
+ if (!sstring.reserve ((_size + 1 ))) {
294
+ DEBUG_HTTPCLIENT (" [HTTP-Client][getString] too less memory to resive as string! need: %d\n " , (_size + 1 ));
295
+ return String (" --too less memory--" );
296
+ }
297
+ }
298
+
299
+ writeToStream (&sstring);
300
+ return sstring;
301
+ }
302
+
268
303
/* *
269
304
* adds Headder to the request
270
305
* @param name
Original file line number Diff line number Diff line change @@ -75,8 +75,10 @@ class httpClient {
75
75
76
76
int getSize (void );
77
77
78
- WiFiClient & getStream (void );
78
+ WiFiClient & getStream (void ) __attribute__ ((deprecated)) ;
79
+ WiFiClient * getStreamPtr (void );
79
80
int writeToStream (Stream * stream);
81
+ String getString (void );
80
82
81
83
protected:
82
84
You can’t perform that action at this time.
0 commit comments