wrapper of TLS library to connect to HTTPS servers
Dependents: HTTPSClientExample
HTTPSClient Class Reference
Simple wrapper of TLS library to send GET request to a server and receive some web pages. More...
#include <HTTPSClient.h>
Public Member Functions | |
bool | connect (const std::string &host) |
Connnect to the given host. | |
int | get (const std::string &path, HTTPHeader *hdr) |
Send a GET request to the host. | |
int | get (const std::string &path, HTTPHeader *hdr, char *data, int length) |
Send a get request and reads (partially) the body. | |
bool | disconnect () |
Disconnect from host. |
Detailed Description
Simple wrapper of TLS library to send GET request to a server and receive some web pages.
Definition at line 12 of file HTTPSClient.h.
Member Function Documentation
bool connect | ( | const std::string & | host ) |
Connnect to the given host.
- Parameters:
-
host A valid hostname (e.g. "mbed.org")
- Returns:
- True if the connection was established with success, false otherwise.
- Note:
- If the client is already connected, it returns false.
Definition at line 11 of file HTTPSClient.cpp.
bool disconnect | ( | ) |
Disconnect from host.
- Returns:
- True if the client disconnected with success, false otherwise.
Definition at line 82 of file HTTPSClient.cpp.
int get | ( | const std::string & | path, |
HTTPHeader * | hdr, | ||
char * | data, | ||
int | length | ||
) |
Send a get request and reads (partially) the body.
- Parameters:
-
path hdr A pointer to an HTTPHeader object. data A pointer to some buffer length Maximum number of bytes to read
- Returns:
- Number of bytes stored in data in range 0..length, or -1 if an error occured.
- Note:
- To check whether this request is sent with success, you must check the status of the HTTPHeader and the value of the integer returned by this function.
Example:
// Assuming that an HTTPSClient object c is connected to a host HTTPHeader hdr; char buffer[256]; int n = c.get("/", &hdr, buffer, 256); if(n > 0 && hdr.getStatus() == HTTP_OK) // GET request sent with success { // do some stuff here.. } else printf("Failed to send get request\n");
- Note:
- If hdr is null, this function does not send anything and directly writes bytes in data. This is particularly useful if you expect large answers (such as webpages) from the host.
Definition at line 61 of file HTTPSClient.cpp.
int get | ( | const std::string & | path, |
HTTPHeader * | hdr | ||
) |
Send a GET request to the host.
- Parameters:
-
path hdr A pointer to an HTTPHeader object.
- Returns:
- Returns 0 if the request was sent with success, or -1 if an error occured.
Definition at line 47 of file HTTPSClient.cpp.
Generated on Thu Jul 21 2022 11:27:49 by 1.7.2