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

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;
}

 

转载于:https://www.cnblogs.com/buyishi/p/9371066.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值