Http/Https客户端操作类 更多...
#include <sttnet.h>
Public 成员函数 | |
| HttpClient (const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="") | |
| HttpClient类的构造函数 更多... | |
| bool | getRequest (const std::string &url, const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=-1) |
| 发送一个GET请求到服务器 更多... | |
| 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) |
| 发送一个POST请求到服务器 更多... | |
| 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) |
| 从tcp套接字发送一个GET请求到服务器 更多... | |
| 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) |
| 发送一个POST请求到服务器 更多... | |
| bool | isReturn () |
| 获取服务器返回响应状态 更多... | |
Public 属性 | |
| std::string | header ="" |
| 服务器返回响应头 更多... | |
| std::string | body ="" |
| 服务器返回响应体 更多... | |
Http/Https客户端操作类
|
inline |
HttpClient类的构造函数
| TLS | true:启用Https加密 false:不启用Https加密 (默认为false不启用) |
| ca | CA 根证书路径(若启用TLS加密则必须填这个 默认空) |
| cert | 客户端证书路径(可选 默认空) |
| key | 客户端私钥路径(可选 默认空) |
| passwd | 私钥解密密码(可选 默认空) |
| bool stt::network::HttpClient::getRequest | ( | const std::string & | url, |
| const std::string & | header = "", |
||
| const std::string & | header1 = "Connection: keep-alive", |
||
| const int & | sec = -1 |
||
| ) |
发送一个GET请求到服务器
| url | http/https的完整url(注意需要显式指定端口和路径) 如:https://google.com 要写成https://google.com:443/ (补全:443和/) |
| header | Http请求头;如果不是用createHeader生成,记得在末尾要加上 。 |
| header1 | HTTP请求头的附加项;如果需要,一定要填入一个有效项;末尾不需要加入 (不能用createHeader)。(默认填入了keepalive项) |
| sec | 阻塞超时时间(s) 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| 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 |
||
| ) |
从tcp套接字发送一个GET请求到服务器
| fd | tcp套接字 |
| ssl | TLS加密套接字 |
| url | http/https的完整url(注意需要显式指定端口和路径) 如:https://google.com 要写成https://google.com:443/ (补全:443和/) |
| header | Http请求头;如果不是用createHeader生成,记得在末尾要加上 。 |
| header1 | HTTP请求头的附加项;如果需要,一定要填入一个有效项;末尾不需要加入 (不能用createHeader)。(默认填入了keepalive项) |
| sec | 阻塞超时时间(s) 阻塞超过这个时间就不会再阻塞了 默认为2s |
|
inline |
获取服务器返回响应状态
| 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 |
||
| ) |
发送一个POST请求到服务器
| url | http/https的完整url(注意需要显式指定端口和路径) 如:https://google.com 要写成https://google.com:443/ (补全:443和/) |
| body | http请求体 |
| header | Http请求头;如果不是用createHeader生成,记得在末尾要加上 。 |
| header1 | HTTP请求头的附加项;如果需要,一定要填入一个有效项;末尾不需要加入 (不能用createHeader)。(默认填入了keepalive项) |
| sec | 阻塞超时时间(s) 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| 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 |
||
| ) |
发送一个POST请求到服务器
| fd | tcp套接字 |
| ssl | TLS加密套接字 |
| url | http/https的完整url(注意需要显式指定端口和路径) 如:https://google.com 要写成https://google.com:443/ (补全:443和/) |
| body | http请求体 |
| header | Http请求头;如果不是用createHeader生成,记得在末尾要加上 。 |
| header1 | HTTP请求头的附加项;如果需要,一定要填入一个有效项;末尾不需要加入 (不能用createHeader)。(默认填入了keepalive项) |
| sec | 阻塞超时时间(s) 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| std::string stt::network::HttpClient::body ="" |
服务器返回响应体
| std::string stt::network::HttpClient::header ="" |
服务器返回响应头
1.8.5