# httpRequest **Repository Path**: sailwon/http-request ## Basic Information - **Project Name**: httpRequest - **Description**: 简单封装libcurl - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-08-22 - **Last Updated**: 2022-08-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 简单封装libcurl ### 方法 #### GET ```c++ auto res = http.Get("https://www.baidu.com"); std::cout << res->res_headers();//返回响应头 std::cout << res->res_cookies_text();//返回Set_Cookies std::cout << res->res_http_code();//返回状态码 std::cout << res->res_error_msg();//返回错误信息 ``` #### POST ```c++ auto res = http.Post("https://www.baidu.com","senddata"); std::cout << res->res_headers();//返回响应头 std::cout << res->res_cookies_text();//返回Set_Cookies std::cout << res->res_http_code();//返回状态码 std::cout << res->res_error_msg();//返回错误信息 ``` #### upload 支持带进度回调 ```c++ auto cb = [](double total, double now)->bool { if (total > 0 && now > 0) { std::cout << (now / total) * 100 << std::endl; } return true; }; cool::downUpInfo info(true,cb); std::vector upinfo; upinfo.emplace_back(cool::UpFromInfo("file", R"(C:\Users\Administrator\Pictures\8.png)", cool::from_type::LOCAL_FILE_PATH)); cool::header h; std::string times = std::to_string(time(NULL)); h << "referer: https://imgurl.org/"; h << "x-requested-with: XMLHttpRequest"; h << "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.57"; auto res = http.req_redirection(false).req_header(h).\ Upfile("https://imgurl.org/upload/ftp", upinfo,&info); std::cout << cool::Encoder::utf8_to_ansi(res->res_text()) << std::endl; //std::cout << cool::Encoder::utf8_to_ansi(res->res_headers()) << std::endl; std::cout << res->res_cookies_text() << std::endl; std::cout << res->res_http_code() << std::endl; ``` #### download 支持带进度回调 ```c++ auto cb = [](double total, double now)->bool { if (total > 0 && now > 0) { std::cout << (now / total) * 100 << std::endl; } return true; }; cool::downUpInfo info(true,cb); res = http.Downfile("https://www.baidu.com", "save file path",&info); ```