|
STTNet
|
Http/Https client operation class. More...
#include <sttnet_English.h>
Public Member Functions | |
| HttpClient (const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="") | |
| Constructor of HttpClient class. More... | |
| bool | getRequest (const std::string &url, const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=-1) |
| Send a GET request to the server. More... | |
| bool | postRequest (const std::string &url, const std::string &body="", const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=-1) |
| Send a POST request to the server. More... | |
| bool | getRequestFromFD (const int &fd, SSL *ssl, const std::string &url, const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=2) |
| Send a GET request to the server from a tcp socket. More... | |
| bool | postRequestFromFD (const int &fd, SSL *ssl, const std::string &url, const std::string &body="", const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=2) |
| Send a POST request to the server. More... | |
| bool | isReturn () |
| Get the server response status. More... | |
Public Attributes | |
| std::string | header = "" |
| Server response header. More... | |
| std::string | body = "" |
| Server response body. More... | |
Http/Https client operation class.
|
inline |
Constructor of HttpClient class.
| TLS | true: Enable Https encryption, false: Do not enable Https encryption (default is false) |
| ca | Path to CA root certificate (must be filled if TLS encryption is enabled, default is empty) |
| cert | Path to client certificate (optional, default is empty) |
| key | Path to client private key (optional, default is empty) |
| passwd | Password for private key decryption (optional, default is empty) |
| bool stt::network::HttpClient::getRequest | ( | const std::string & | url, |
| const std::string & | header = "", |
||
| const std::string & | header1 = "Connection: keep-alive", |
||
| const int & | sec = -1 |
||
| ) |
Send a GET request to the server.
| url | Complete http/https url (note that the port and path need to be specified explicitly) e.g., https://google.com should be written as https://google.com:443/ (complete with :443 and /) |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (keepalive item is filled in by default) |
| sec | blocking timeout (s) Blocking beyond this time will no longer block The default is -1, i.e. infinite waiting |
| bool stt::network::HttpClient::getRequestFromFD | ( | const int & | fd, |
| SSL * | ssl, | ||
| const std::string & | url, | ||
| const std::string & | header = "", |
||
| const std::string & | header1 = "Connection: keep-alive", |
||
| const int & | sec = 2 |
||
| ) |
Send a GET request to the server from a tcp socket.
| fd | tcp socket |
| ssl | TLS encrypted socket |
| url | Complete http/https url (note that the port and path need to be specified explicitly) e.g., https://google.com should be written as https://google.com:443/ (complete with :443 and /) |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (keepalive item is filled in by default) |
| sec | blocking timeout (s) Blocking beyond this time will no longer block The default is 2s |
|
inline |
Get the server response status.
| bool stt::network::HttpClient::postRequest | ( | const std::string & | url, |
| const std::string & | body = "", |
||
| const std::string & | header = "", |
||
| const std::string & | header1 = "Connection: keep-alive", |
||
| const int & | sec = -1 |
||
| ) |
Send a POST request to the server.
| url | Complete http/https url (note that the port and path need to be specified explicitly) e.g., https://google.com should be written as https://google.com:443/ (complete with :443 and /) |
| body | Http request body |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (keepalive item is filled in by default) |
| sec | blocking timeout (s) Blocking beyond this time will no longer block The default is -1, i.e. infinite waiting |
| bool stt::network::HttpClient::postRequestFromFD | ( | const int & | fd, |
| SSL * | ssl, | ||
| const std::string & | url, | ||
| const std::string & | body = "", |
||
| const std::string & | header = "", |
||
| const std::string & | header1 = "Connection: keep-alive", |
||
| const int & | sec = 2 |
||
| ) |
Send a POST request to the server.
| fd | tcp socket |
| ssl | TLS encrypted socket |
| url | Complete http/https url (note that the port and path need to be specified explicitly) e.g., https://google.com should be written as https://google.com:443/ (complete with :443 and /) |
| body | http request body |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (keepalive item is filled in by default) |
| sec | blocking timeout (s) Blocking beyond this time will no longer block The default is 2s |
| std::string stt::network::HttpClient::body = "" |
Server response body.
| std::string stt::network::HttpClient::header = "" |
Server response header.
1.8.5