ESP8266
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
HTTPClient Class Reference

Classes

struct  RequestArgument
 

Public Member Functions

 HTTPClient ()
 
 ~HTTPClient ()
 
void begin (const char *url, const char *httpsFingerprint="")
 
void begin (String url, String httpsFingerprint="")
 
void begin (const char *host, uint16_t port, const char *url="/", bool https=false, const char *httpsFingerprint="")
 
void begin (String host, uint16_t port, String url="/", bool https=false, String httpsFingerprint="")
 
void end (void)
 
bool connected (void)
 
void setReuse (bool reuse)
 
void setUserAgent (const char *userAgent)
 keep-alive More...
 
void setAuthorization (const char *user, const char *password)
 
void setAuthorization (const char *auth)
 
void setTimeout (uint16_t timeout)
 
int GET ()
 request handling More...
 
int POST (uint8_t *payload, size_t size)
 
int POST (String payload)
 
int sendRequest (const char *type, uint8_t *payload=NULL, size_t size=0)
 
int sendRequest (const char *type, Stream *stream, size_t size=0)
 
void addHeader (const String &name, const String &value, bool first=false)
 
void collectHeaders (const char *headerKeys[], const size_t headerKeysCount)
 Response handling. More...
 
String header (const char *name)
 
String header (size_t i)
 
String headerName (size_t i)
 
int headers ()
 
bool hasHeader (const char *name)
 
int getSize (void)
 
WiFiClientgetStream (void) __attribute__((deprecated))
 
WiFiClientgetStreamPtr (void)
 
int writeToStream (Stream *stream)
 
String getString (void)
 

Static Public Member Functions

static String errorToString (int error)
 

Protected Member Functions

bool connect (void)
 
bool sendHeader (const char *type)
 
int handleHeaderResponse ()
 

Protected Attributes

WiFiClient_tcp
 
WiFiClientSecure_tcps
 
String _host
 request handling More...
 
uint16_t _port
 
bool _reuse
 
uint16_t _tcpTimeout
 
String _url
 
bool _https
 
String _httpsFingerprint
 
String _Headers
 
String _userAgent
 
String _base64Authorization
 
RequestArgument_currentHeaders
 Response handling. More...
 
size_t _headerKeysCount
 
int _returnCode
 
int _size
 
bool _canReuse
 

Constructor & Destructor Documentation

HTTPClient::HTTPClient ( )

ESP8266HTTPClient.cpp

Created on: 02.11.2015

Copyright (c) 2015 Markus Sattler. All rights reserved. This file is part of the ESP8266HTTPClient for Arduino.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA constractor

HTTPClient::~HTTPClient ( )

deconstractor

Member Function Documentation

void HTTPClient::addHeader ( const String &  name,
const String &  value,
bool  first = false 
)

adds Header to the request

Parameters
name
value
first
void HTTPClient::begin ( const char *  url,
const char *  httpsFingerprint = "" 
)

phasing the url for all needed informations

Parameters
urlconst char *
httpsFingerprintconst char *
void HTTPClient::begin ( String  url,
String  httpsFingerprint = "" 
)

phasing the url for all needed informations

Parameters
urlString
httpsFingerprintString
void HTTPClient::begin ( const char *  host,
uint16_t  port,
const char *  url = "/",
bool  https = false,
const char *  httpsFingerprint = "" 
)

begin

Parameters
hostconst char *
portuint16_t
urlconst char *
httpsbool
httpsFingerprintconst char *
void HTTPClient::begin ( String  host,
uint16_t  port,
String  url = "/",
bool  https = false,
String  httpsFingerprint = "" 
)
void HTTPClient::collectHeaders ( const char *  headerKeys[],
const size_t  headerKeysCount 
)

Response handling.

bool HTTPClient::connect ( void  )
protected

init TCP connection and handle ssl verify if needed

Returns
true if connection is ok
bool HTTPClient::connected ( void  )

connected

Returns
connected status
void HTTPClient::end ( void  )

end called after the payload is handled

String HTTPClient::errorToString ( int  error)
static

converts error code to String

Parameters
errorint
Returns
String
int HTTPClient::GET ( )

request handling

send a GET request

Returns
http code
int HTTPClient::getSize ( void  )

size of message body / payload

Returns
-1 if no info or > 0 when Content-Length is set by server
WiFiClient & HTTPClient::getStream ( void  )

deprecated Note: this is not working with https! returns the stream of the tcp connection

Returns
WiFiClient
WiFiClient * HTTPClient::getStreamPtr ( void  )

returns the stream of the tcp connection

Returns
WiFiClient *
String HTTPClient::getString ( void  )

return all payload as String (may need lot of ram or trigger out of memory!)

Returns
String
int HTTPClient::handleHeaderResponse ( )
protected

reads the response from the server

Returns
int http code
bool HTTPClient::hasHeader ( const char *  name)
String HTTPClient::header ( const char *  name)
String HTTPClient::header ( size_t  i)
String HTTPClient::headerName ( size_t  i)
int HTTPClient::headers ( )
int HTTPClient::POST ( uint8_t *  payload,
size_t  size 
)

sends a post request to the server

Parameters
payloaduint8_t *
sizesize_t
Returns
http code
int HTTPClient::POST ( String  payload)
bool HTTPClient::sendHeader ( const char *  type)
protected

sends HTTP request header

Parameters
type(GET, POST, ...)
Returns
status
int HTTPClient::sendRequest ( const char *  type,
uint8_t *  payload = NULL,
size_t  size = 0 
)

sendRequest

Parameters
typeconst char * "GET", "POST", ....
payloaduint8_t * data for the message body if null not send
sizesize_t size for the message body if 0 not send
Returns
-1 if no info or > 0 when Content-Length is set by server
int HTTPClient::sendRequest ( const char *  type,
Stream stream,
size_t  size = 0 
)

sendRequest

Parameters
typeconst char * "GET", "POST", ....
streamStream * data stream for the message body
sizesize_t size for the message body if 0 not Content-Length is send
Returns
-1 if no info or > 0 when Content-Length is set by server
void HTTPClient::setAuthorization ( const char *  user,
const char *  password 
)

set the Authorizatio for the http request

Parameters
userconst char *
passwordconst char *
void HTTPClient::setAuthorization ( const char *  auth)

set the Authorizatio for the http request

Parameters
authconst char * base64
void HTTPClient::setReuse ( bool  reuse)

try to reuse the connection to the server keep-alive

Parameters
reusebool
void HTTPClient::setTimeout ( uint16_t  timeout)

set the timeout for the TCP connection

Parameters
timeoutunsigned int
void HTTPClient::setUserAgent ( const char *  userAgent)

keep-alive

set User Agent

Parameters
userAgentconst char *
int HTTPClient::writeToStream ( Stream stream)

write all message body / payload to Stream

Parameters
streamStream *
Returns
bytes written ( negative values are error codes )

Member Data Documentation

String HTTPClient::_base64Authorization
protected
bool HTTPClient::_canReuse
protected
RequestArgument* HTTPClient::_currentHeaders
protected

Response handling.

size_t HTTPClient::_headerKeysCount
protected
String HTTPClient::_Headers
protected
String HTTPClient::_host
protected

request handling

bool HTTPClient::_https
protected
String HTTPClient::_httpsFingerprint
protected
uint16_t HTTPClient::_port
protected
int HTTPClient::_returnCode
protected
bool HTTPClient::_reuse
protected
int HTTPClient::_size
protected
WiFiClient* HTTPClient::_tcp
protected
WiFiClientSecure* HTTPClient::_tcps
protected
uint16_t HTTPClient::_tcpTimeout
protected
String HTTPClient::_url
protected
String HTTPClient::_userAgent
protected