Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CyaSSL
Dependents: MTS-Socket MTS-Socket
HTTPClient Class Reference
A simple HTTP Client The HTTPClient is composed of:
- The actual client (HTTPClient)
- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes)
#include <HTTPClient.h>
Public Member Functions | |
HTTPClient () | |
Instantiate the HTTP client. | |
HTTPResult | basicAuth (const char *user, const char *password) |
Provides a basic authentification feature (Base64 encoded username and password) Pass two NULL pointers to switch back to no authentication. | |
HTTPResult | get (const char *url, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a GET request on the URL Blocks until completion. | |
HTTPResult | get (const char *url, char *result, size_t maxResultLen, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a GET request on the URL Blocks until completion This is a helper to directly get a piece of text from a HTTP result. | |
HTTPResult | post (const char *url, const IHTTPDataOut &dataOut, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a POST request on the URL Blocks until completion. | |
HTTPResult | put (const char *url, const IHTTPDataOut &dataOut, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a PUT request on the URL Blocks until completion. | |
HTTPResult | del (const char *url, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a DELETE request on the URL Blocks until completion. | |
int | getHTTPResponseCode () |
Get last request's HTTP response code. | |
void | setHeader (const char *header) |
Set headers to be included in the following HTTP requests. | |
HTTPResult | setSSLversion (int minorV) |
Set SSL/TLS version. | |
HTTPResult | addRootCACertificate (const char *cert) |
Stores a root CA certificate for host authentication of a website. | |
void | setPeerVerification (SSLMethod method) |
Sets the verification for peer authenticity when connecting with SSL. |
Detailed Description
A simple HTTP Client The HTTPClient is composed of:
- The actual client (HTTPClient)
- Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes)
Definition at line 63 of file HTTPClient.h.
Constructor & Destructor Documentation
HTTPClient | ( | ) |
Instantiate the HTTP client.
Definition at line 113 of file HTTPClient.cpp.
Member Function Documentation
HTTPResult addRootCACertificate | ( | const char * | cert ) |
Stores a root CA certificate for host authentication of a website.
Each new line should end with "\r\n" including the last line of each certificate. Pass a pointer to the char array containing the certificate stored as a c-string. Pass a NULL pointer to reset all certificates stored. (Can pass in multiple certificates with one function call if the array contains concatenated certificates)
Definition at line 221 of file HTTPClient.cpp.
HTTPResult basicAuth | ( | const char * | user, |
const char * | password | ||
) |
Provides a basic authentification feature (Base64 encoded username and password) Pass two NULL pointers to switch back to no authentication.
- Parameters:
-
user username to use for authentication, must remain valid durlng the whole HTTP session user password to use for authentication, must remain valid durlng the whole HTTP session
Definition at line 145 of file HTTPClient.cpp.
HTTPResult del | ( | const char * | url, |
IHTTPDataIn * | pDataIn, | ||
int | timeout = HTTP_CLIENT_DEFAULT_TIMEOUT |
||
) |
Execute a DELETE request on the URL Blocks until completion.
- Parameters:
-
url : url on which to execute the request. Format of: http[s]://<host>/[<path>][fragment_id] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 191 of file HTTPClient.cpp.
HTTPResult get | ( | const char * | url, |
IHTTPDataIn * | pDataIn, | ||
int | timeout = HTTP_CLIENT_DEFAULT_TIMEOUT |
||
) |
Execute a GET request on the URL Blocks until completion.
- Parameters:
-
url : url on which to execute the request. Format of: http[s]://<host>/[<path>][fragment_id] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 170 of file HTTPClient.cpp.
HTTPResult get | ( | const char * | url, |
char * | result, | ||
size_t | maxResultLen, | ||
int | timeout = HTTP_CLIENT_DEFAULT_TIMEOUT |
||
) |
Execute a GET request on the URL Blocks until completion This is a helper to directly get a piece of text from a HTTP result.
- Parameters:
-
url : url on which to execute the request. Format of: http[s]://<host>/[<path>][fragment_id] result : pointer to a char array in which the result will be stored maxResultLen : length of the char array (including space for the NULL-terminating char) timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 175 of file HTTPClient.cpp.
int getHTTPResponseCode | ( | ) |
Get last request's HTTP response code.
- Returns:
- The HTTP response code of the last request
Definition at line 197 of file HTTPClient.cpp.
HTTPResult post | ( | const char * | url, |
const IHTTPDataOut & | dataOut, | ||
IHTTPDataIn * | pDataIn, | ||
int | timeout = HTTP_CLIENT_DEFAULT_TIMEOUT |
||
) |
Execute a POST request on the URL Blocks until completion.
- Parameters:
-
url : url on which to execute the request. Format of: http[s]://<host>/[<path>][fragment_id] dataOut : a IHTTPDataOut instance that contains the data that will be posted pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 181 of file HTTPClient.cpp.
HTTPResult put | ( | const char * | url, |
const IHTTPDataOut & | dataOut, | ||
IHTTPDataIn * | pDataIn, | ||
int | timeout = HTTP_CLIENT_DEFAULT_TIMEOUT |
||
) |
Execute a PUT request on the URL Blocks until completion.
- Parameters:
-
url : url on which to execute the request. Format of: http[s]://<host>/[<path>][fragment_id] dataOut : a IHTTPDataOut instance that contains the data that will be put pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 186 of file HTTPClient.cpp.
void setHeader | ( | const char * | header ) |
Set headers to be included in the following HTTP requests.
Pass a NULL pointer to reset the headers stored. Make sure the headers are formatted with a "\r\n" after each header.
- Parameters:
-
header pointer to array containing the headers to be added
Definition at line 202 of file HTTPClient.cpp.
void setPeerVerification | ( | SSLMethod | method ) |
Sets the verification for peer authenticity when connecting with SSL.
- Parameters:
-
method specifies the method to use for peer verification Sets the client to not verify the peer's certificates Sets the client to verify the peer's certificates but skips if certificates unavailable Sets the client to verify the peer's certificates and throw an error if the certificates are unavailable.
Definition at line 248 of file HTTPClient.cpp.
HTTPResult setSSLversion | ( | int | minorV ) |
Set SSL/TLS version.
- Parameters:
-
minorV integer witha a value between 0 and 3 0: SSL3, 1: TLS1.0, 2: TLS1.1, 3: TLS1.2
- Returns:
- HTTPResult based on success
Definition at line 213 of file HTTPClient.cpp.
Generated on Wed Jul 13 2022 05:18:11 by
