Public Member Functions | |
HttpClient (Client &aClient) | |
void | beginRequest () |
void | endRequest () |
int | get (const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | get (const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | get (const IPAddress &aServerAddress, const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | get (const IPAddress &aServerAddress, const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | post (const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | post (const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | post (const IPAddress &aServerAddress, const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | post (const IPAddress &aServerAddress, const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | put (const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | put (const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | put (const IPAddress &aServerAddress, const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aUserAgent=NULL) |
int | put (const IPAddress &aServerAddress, const char *aServerName, const char *aURLPath, const char *aUserAgent=NULL) |
int | startRequest (const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aHttpMethod, const char *aUserAgent) |
int | startRequest (const IPAddress &aServerAddress, const char *aServerName, uint16_t aServerPort, const char *aURLPath, const char *aHttpMethod, const char *aUserAgent) |
void | sendHeader (const char *aHeader) |
void | sendHeader (const char *aHeaderName, const char *aHeaderValue) |
void | sendHeader (const char *aHeaderName, const int aHeaderValue) |
void | sendBasicAuth (const char *aUser, const char *aPassword) |
void | finishRequest () |
int | responseStatusCode () |
int | readHeader () |
int | skipResponseHeaders () |
bool | endOfHeadersReached () |
bool | endOfBodyReached () |
virtual bool | endOfStream () |
virtual bool | completed () |
int | contentLength () |
virtual size_t | write (uint8_t aByte) |
virtual size_t | write (const uint8_t *aBuffer, size_t aSize) |
virtual int | available () |
virtual int | read () |
virtual int | read (uint8_t *buf, size_t size) |
virtual int | peek () |
virtual void | flush () |
virtual int | connect (IPAddress ip, uint16_t port) |
virtual int | connect (const char *host, uint16_t port) |
virtual void | stop () |
virtual uint8_t | connected () |
virtual | operator bool () |
virtual uint32_t | httpResponseTimeout () |
virtual void | setHttpResponseTimeout (uint32_t timeout) |
Static Public Attributes | |
static const int | kNoContentLengthHeader =-1 |
static const uint16_t | kHttpPort =80 |
static const char * | kUserAgent |
Protected Types | |
enum | tHttpState { eIdle, eRequestStarted, eRequestSent, eReadingStatusCode, eStatusCodeRead, eReadingContentLength, eSkipToEndOfHeader, eLineStartingCRFound, eReadingBody } |
Protected Member Functions | |
void | resetState () |
int | sendInitialHeaders (const char *aServerName, IPAddress aServerIP, uint16_t aPort, const char *aURLPath, const char *aHttpMethod, const char *aUserAgent) |
void | finishHeaders () |
Protected Attributes | |
Client * | iClient |
tHttpState | iState |
int | iStatusCode |
int | iContentLength |
int | iBodyLengthConsumed |
const char * | iContentLengthPtr |
IPAddress | iProxyAddress |
uint16_t | iProxyPort |
uint32_t | iHttpResponseTimeout |
Static Protected Attributes | |
static const int | kHttpWaitForDataDelay = 1000 |
static const int | kHttpResponseTimeout = 30*1000 |
static const char * | kContentLengthPrefix |
|
protected |
HttpClient | ( | Client & | aClient | ) |
|
virtual |
void beginRequest | ( | ) |
Start a more complex request. Use this when you need to send additional headers in the request, but you will also need to call endRequest() when you are finished.
|
virtual |
|
virtual |
|
virtual |
|
virtual |
int contentLength | ( | ) |
Return the length of the body.
bool endOfBodyReached | ( | ) |
Test whether the end of the body has been reached. Only works if the Content-Length header was returned by the server
bool endOfHeadersReached | ( | ) |
Test whether all of the response headers have been consumed.
|
virtual |
void endRequest | ( | ) |
End a more complex request. Use this when you need to have sent additional headers in the request, but you will also need to call beginRequest() at the start.
|
protected |
void finishRequest | ( | ) |
Finish sending the HTTP request. This basically just sends the blank line to signify the end of the request
|
virtual |
int get | ( | const char * | aServerName, |
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a GET request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int get | ( | const char * | aServerName, |
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a GET request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int get | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a GET request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int get | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a GET request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
|
virtual |
|
virtual |
|
virtual |
int post | ( | const char * | aServerName, |
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a POST request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int post | ( | const char * | aServerName, |
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a POST request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int post | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a POST request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int post | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a POST request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int put | ( | const char * | aServerName, |
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a PUT request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int put | ( | const char * | aServerName, |
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a PUT request.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int put | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a PUT request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int put | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
const char * | aURLPath, | ||
const char * | aUserAgent = NULL |
||
) |
Connect to the server and start to send a PUT request. This version connects doesn't perform a DNS lookup and just connects to the given IP address.
aServerAddress | IP address of the server to connect to |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aURLPath | Url to request |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
|
virtual |
Read the next byte from the server.
|
virtual |
int readHeader | ( | ) |
Read the next character of the response headers. This functions in the same way as read() but to be used when reading through the headers. Check whether or not the end of the headers has been reached by calling endOfHeadersReached(), although after that point this will still return data as read() would, but slightly less efficiently
|
protected |
Reset internal state data back to the "just initialised" state
int responseStatusCode | ( | ) |
Get the HTTP status code contained in the response. For example, 200 for successful request, 404 for file not found, etc.
void sendBasicAuth | ( | const char * | aUser, |
const char * | aPassword | ||
) |
Send a basic authentication header. This will encode the given username and password, and send them in suitable header line for doing Basic Authentication.
aUser | Username for the authorization |
aPassword | Password for the user aUser |
void sendHeader | ( | const char * | aHeader | ) |
Send an additional header line. This can only be called in between the calls to startRequest and finishRequest.
aHeader | Header line to send, in its entirety (but without the trailing CRLF. E.g. "Authorization: Basic YQDDCAIGES" |
void sendHeader | ( | const char * | aHeaderName, |
const char * | aHeaderValue | ||
) |
Send an additional header line. This is an alternate form of sendHeader() which takes the header name and content as separate strings. The call will add the ": " to separate the header, so for example, to send a XXXXXX header call sendHeader("XXXXX", "Something")
aHeaderName | Type of header being sent |
aHeaderValue | Value for that header |
void sendHeader | ( | const char * | aHeaderName, |
const int | aHeaderValue | ||
) |
Send an additional header line. This is an alternate form of sendHeader() which takes the header name and content separately but where the value is provided as an integer. The call will add the ": " to separate the header, so for example, to send a XXXXXX header call sendHeader("XXXXX", 123)
aHeaderName | Type of header being sent |
aHeaderValue | Value for that header |
|
protected |
Send the first part of the request and the initial headers.
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerIP | IP address of the server (only used if we're going through a proxy and aServerName is NULL |
aPort | Port of the server being connected to. |
aURLPath | Url to request |
aHttpMethod | Type of HTTP request to make, e.g. "GET", "POST", etc. |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
|
virtual |
int skipResponseHeaders | ( | ) |
Skip any response headers to get to the body. Use this if you don't want to do any special processing of the headers returned in the response. You can also use it after you've found all of the headers you're interested in, and just want to get on with processing the body.
int startRequest | ( | const char * | aServerName, |
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aHttpMethod, | ||
const char * | aUserAgent | ||
) |
Connect to the server and start to send the request.
aServerName | Name of the server being connected to. |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aHttpMethod | Type of HTTP request to make, e.g. "GET", "POST", etc. |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
int startRequest | ( | const IPAddress & | aServerAddress, |
const char * | aServerName, | ||
uint16_t | aServerPort, | ||
const char * | aURLPath, | ||
const char * | aHttpMethod, | ||
const char * | aUserAgent | ||
) |
Connect to the server and start to send the request.
aServerAddress | IP address of the server to connect to. |
aServerName | Name of the server being connected to. If NULL, the "Host" header line won't be sent |
aServerPort | Port to connect to on the server |
aURLPath | Url to request |
aHttpMethod | Type of HTTP request to make, e.g. "GET", "POST", etc. |
aUserAgent | User-Agent string to send. If NULL the default user-agent kUserAgent will be sent |
|
virtual |
|
virtual |
|
virtual |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
static |
|
staticprotected |
|
staticprotected |
|
static |
|
static |