1. 程式人生 > >使用libcurl的包裝庫cpr發起http請求

使用libcurl的包裝庫cpr發起http請求

cout main title pow dsa ext lan text post

cpr GitHub地址https://github.com/whoshuu/cpr

簡單示例:cpr_http_request.cpp

#include <iostream>
#include <cpr/cpr.h>
int main()
{
    std::string requestAddress("https://api.eyekey.com/face/Check/checking");
    std::string requestParams("app_id=f89ae61fd63d4a63842277e9144a6bd2&app_key=af1cd33549c54b27ae24aeb041865da2&url=http%3A%2F%2Fpicview01.baomihua.com%2Fphotos%2F20120713%2Fm_14_634778197959062500_40614445.jpg
"); std::cout << "GET Sample:" << std::endl; const cpr::Response &responseForGet = cpr::Get(cpr::Url(requestAddress.append("?" + requestParams))); std::cout << \t << responseForGet.status_code << std::endl; std::cout << \t << responseForGet.text << std::endl; std::cout
<< "POST Sample:" << std::endl; cpr::Multipart multipart{ { "app_id", "f89ae61fd63d4a63842277e9144a6bd2" }, { "app_key", "af1cd33549c54b27ae24aeb041865da2" }, {"url", "https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=18bb0cc2dd1373f0f53f68999c342cc6/caef76094b36acafe725024570d98d1000e99c46.jpg
"} }; const cpr::Response &responseForPost = cpr::Post(cpr::Url(requestAddress), multipart); std::cout << \t << responseForPost.status_code << std::endl; std::cout << \t << responseForPost.text << std::endl; std::system("pause"); return 0; }

使用libcurl的包裝庫cpr發起http請求