分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 02:06责任编辑:郭大石关键词:urlhttp

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

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved