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.
Dependents: Sample_HTTPClient Sample_HTTPClient LWM2M_NanoService_Ethernet LWM2M_NanoService_Ethernet ... more
Fork of HTTPClient by
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. | |
| void | 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. | |
| void | customHeaders (const char **headers, size_t pairs) |
| Set custom headers for request. | |
| 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 | setMaxRedirections (int i=1) |
| Set the maximum number of automated redirections. | |
| const char * | getLocation () |
| get the redirect location url | |
Static Public Member Functions | |
| static const char * | GetErrorMessage (HTTPResult res) |
| Get the text form of the error number. | |
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 56 of file HTTPClient.h.
Constructor & Destructor Documentation
| HTTPClient | ( | ) |
Instantiate the HTTP client.
Definition at line 55 of file HTTPClient.cpp.
Member Function Documentation
| void 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:
-
[in] user username to use for authentication, must remain valid durlng the whole HTTP session [in] user password to use for authentication, must remain valid durlng the whole HTTP session
Definition at line 97 of file HTTPClient.cpp.
| void customHeaders | ( | const char ** | headers, |
| size_t | pairs | ||
| ) |
Set custom headers for request.
Pass NULL, 0 to turn off custom headers.
const char * hdrs[] = { "Connection", "keep-alive", "Accept", "text/html", "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64)", "Accept-Encoding", "gzip,deflate,sdch", "Accept-Language", "en-US,en;q=0.8", }; http.basicAuth("username", "password"); http.customHeaders(hdrs, 5);
- Parameters:
-
[in] headers an array (size multiple of two) key-value pairs, must remain valid during the whole HTTP session [in] pairs number of key-value pairs
Definition at line 114 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:
-
[in] url : url on which to execute the request [in,out] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL [in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 144 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:
-
[in] url : url on which to execute the request [in,out] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL [in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 121 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:
-
[in] url : url on which to execute the request [out] result : pointer to a char array in which the result will be stored [in] maxResultLen : length of the char array (including space for the NULL-terminating char) [in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 127 of file HTTPClient.cpp.
| const char * GetErrorMessage | ( | HTTPResult | res ) | [static] |
Get the text form of the error number.
Gets a pointer to a text message that described the result code.
- Parameters:
-
[in] res is the HTTPResult code to translate to text.
- Returns:
- a pointer to a text message.
<Success
<Processing
<url Parse error
<Could not resolve name
<Protocol error
<HTTP 404 Error
<HTTP 403 Error
<HTTP xxx error
<Connection timeout
<Connection error
<Connection was closed by remote host
Definition at line 75 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 150 of file HTTPClient.cpp.
| const char* getLocation | ( | ) |
get the redirect location url
- Returns:
- const char pointer to the url.
Definition at line 168 of file HTTPClient.h.
| 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:
-
[in] url : url on which to execute the request [out] dataOut : a IHTTPDataOut instance that contains the data that will be posted [in,out] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL [in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 134 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:
-
[in] url : url on which to execute the request [in] dataOut : a IHTTPDataOut instance that contains the data that will be put [in,out] pDataIn : pointer to an IHTTPDataIn instance that will collect the data returned by the request, can be NULL [in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
- Returns:
- 0 on success, HTTP error (<0) on failure
Definition at line 139 of file HTTPClient.cpp.
| void setMaxRedirections | ( | int | i = 1 ) |
Set the maximum number of automated redirections.
- Parameters:
-
[in] i is the number of redirections. Values < 1 are set to 1.
Definition at line 155 of file HTTPClient.cpp.
Generated on Tue Jul 12 2022 17:30:36 by
1.7.2
