1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-23 08:45:22 +03:00

add examples/BasicHttpClient/BasicHttpClient.ino

fix get size
only fingerprint when strlen > 0
This commit is contained in:
Markus Sattler
2015-11-22 11:09:48 +01:00
parent 5e1a65609c
commit 1e7b9688a5
3 changed files with 99 additions and 12 deletions

View File

@ -36,7 +36,7 @@ httpClient::httpClient() {
_currentHeaders = NULL;
_returnCode = 0;
_size = 0;
_size = -1;
}
httpClient::~httpClient() {
@ -51,11 +51,18 @@ httpClient::~httpClient() {
}
void httpClient::begin(const char *host, uint16_t port, const char * url, bool https, const char * httpsFingerprint) {
_host = host;
_port = port;
_url = url;
_https = https;
_httpsFingerprint = httpsFingerprint;
_returnCode = 0;
_size = -1;
_Headers = "";
}
void httpClient::begin(String host, uint16_t port, String url, bool https, String httpsFingerprint) {
@ -121,6 +128,15 @@ int httpClient::POST(String payload) {
return POST((uint8_t *) payload.c_str(), payload.length());
}
/**
* size of message body / payload
* @return -1 if no info or > 0 when Content-Length is set by server
*/
int httpClient::getSize(void) {
return _size;
}
/**
* returns the stram of the tcp connection
* @return WiFiClient
@ -194,13 +210,7 @@ bool httpClient::hasHeader(const char* name) {
return false;
}
/**
* size of message body / payload
* @return 0 if no info or > 0 when Content-Length is set by server
*/
size_t httpClient::getSize(void) {
return _size;
}
/**
* init TCP connection and handle ssl verify if needed
@ -209,7 +219,7 @@ size_t httpClient::getSize(void) {
bool httpClient::connect(void) {
if(connected()) {
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected!\n");
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, reuse!\n");
return true;
}
@ -229,7 +239,7 @@ bool httpClient::connect(void) {
DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u.\n", _host.c_str(), _port);
if(_https) {
if(_https && _httpsFingerprint.length() > 0) {
if(_tcps->verify(_httpsFingerprint.c_str(), _host.c_str())) {
DEBUG_HTTPCLIENT("[HTTP-Client] https certificate matches\n");
} else {

View File

@ -59,7 +59,7 @@ class httpClient {
bool hasHeader(const char* name); // check if header exists
size_t getSize(void);
int getSize(void);
WiFiClient & getStream(void);
@ -89,7 +89,7 @@ class httpClient {
size_t _headerKeysCount;
int _returnCode;
size_t _size;
int _size;
bool connect(void);