mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
add getString function
This commit is contained in:
parent
8b67051d1e
commit
e4a5250a1a
@ -25,6 +25,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <StreamString.h>
|
||||
|
||||
#include "ESP8266httpClient.h"
|
||||
|
||||
@ -198,6 +199,7 @@ int httpClient::getSize(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* deprecated Note: this is not working with https!
|
||||
* returns the stram of the tcp connection
|
||||
* @return WiFiClient
|
||||
*/
|
||||
@ -211,6 +213,20 @@ WiFiClient & httpClient::getStream(void) {
|
||||
// todo return error?
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the stram of the tcp connection
|
||||
* @return WiFiClient *
|
||||
*/
|
||||
WiFiClient * httpClient::getStreamPtr(void) {
|
||||
if(connected()) {
|
||||
return _tcp;
|
||||
}
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] no stream to return!?\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WiFiClient * getStreamPtr(void);
|
||||
/**
|
||||
* write all message body / payload to Stream
|
||||
* @param stream Stream *
|
||||
@ -265,6 +281,25 @@ int httpClient::writeToStream(Stream * stream) {
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
/**
|
||||
* return all payload as String (may need lot of ram or trigger out of memmory!)
|
||||
* @return String
|
||||
*/
|
||||
String httpClient::getString(void) {
|
||||
StreamString sstring;
|
||||
|
||||
if(_size) {
|
||||
// try to reserve needed memmory
|
||||
if(!sstring.reserve((_size + 1))) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][getString] too less memory to resive as string! need: %d\n", (_size + 1));
|
||||
return String("--too less memory--");
|
||||
}
|
||||
}
|
||||
|
||||
writeToStream(&sstring);
|
||||
return sstring;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds Headder to the request
|
||||
* @param name
|
||||
|
@ -75,8 +75,10 @@ class httpClient {
|
||||
|
||||
int getSize(void);
|
||||
|
||||
WiFiClient & getStream(void);
|
||||
WiFiClient & getStream(void) __attribute__ ((deprecated)) ;
|
||||
WiFiClient * getStreamPtr(void);
|
||||
int writeToStream(Stream * stream);
|
||||
String getString(void);
|
||||
|
||||
protected:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user