|
STTNet 0.7.0
|
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 根证书文件路径;留空时使用操作系统默认信任库。 |
| 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 生成,末尾应包含 CRLF。 |
| header1 | HTTP 请求头附加项;末尾不需要加入 CRLF(默认 keep-alive)。 |
| 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 生成,末尾应包含 CRLF。 |
| header1 | HTTP 请求头附加项;末尾不需要加入 CRLF(默认 keep-alive)。 |
| 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 生成,末尾应包含 CRLF。 |
| header1 | HTTP 请求头附加项;末尾不需要加入 CRLF(默认 keep-alive)。 |
| 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 生成,末尾应包含 CRLF。 |
| header1 | HTTP 请求头附加项;末尾不需要加入 CRLF(默认 keep-alive)。 |
| sec | 阻塞超时时间(s) 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| std::string stt::network::HttpClient::body ="" |
服务器返回响应体
| std::string stt::network::HttpClient::header ="" |
服务器返回响应头