码迷,mamicode.com
首页 > Web开发 > 详细

使用libcurl的包装库cpr发起http请求

时间:2018-07-26 14:53:34      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:return   .text   int   add   style   const   ESS   简单   ref   

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请求

标签:return   .text   int   add   style   const   ESS   简单   ref   

原文地址:https://www.cnblogs.com/buyishi/p/9371066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!