https://github.com/GitOyoung/SE.git
其中的http部分属于本文重点介绍内容,具体如下: 1. 使用到的类包括se::network::http::Request, se::network::http::Client以及se::network::http::Response三个类 2. se::network::http::Request表示客户端发起的http请求,se::network::http::Client表示http客户端,se::network::http::Response表示http响应结果 3. 使用实例代码如下:
se::network::http::Client http; se::network::http::Request req("www.xxxx.com"); req.header("Content-Type", "application/json;charset=UTF-8"); req.body("{\"name\":\"Xiaoming\", \"what\":\"is SB\"}"); std::string body = http.post(req).response().body(); //方式1 http.post(req).response([](const se::network::http::Response& res) { std::string body = res.body(); });se::network::http::Request也支持query和form-data 使用query时
req.query("key","hjdfkhjsgdhjfksjf");使用form-data时,需要先设置header
req.header("Content-Type", "multipart/form-data"); se::network::http::Request::FormData formData; formData.type = se::network::http::Request::FORM_NAME_CONTENT; formData.name = "image_url"; formData.content = "https://www.faceplusplus.com.cn/images/detection/group-case.jpg" req.formdata(formData); http.post(req).response();使用form-data也可以提交文件
std::string filePath("./image.png"); formData.type = se::network::http::Request::FORM_NAME_FILE; formData.name = "image_file"; formData.file = filePath; req.formdata(formData);后续功能都会进一步完善,出现的bug也希望大牛能够指点一二好改进