当前位置:网站首页>【无标题】
【无标题】
2022-07-27 03:06:00 【小涵涵】
crow
crow和flask都是web框架,能够快速搭建web server服务
#include "crow.h"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")([](){
return "Hello world";
});
CROW_ROUTE(app,"/hello/<int>")
([](int count){
if (count > 100)
return crow::response(400);
std::ostringstream os;
os << count << " bottles of beer!";
return crow::response(os.str());
});
CROW_ROUTE(app, "/params")
([](const crow::request& req){
std::ostringstream os;
os << "Params: " << req.url_params << "\n\n";
os << "The key 'foo' was " << (req.url_params.get("foo") == nullptr ? "not " : "") << "found.\n";
if(req.url_params.get("pew") != nullptr) {
double countD = boost::lexical_cast<double>(req.url_params.get("pew"));
os << "The value of 'pew' is " << countD << '\n';
}
auto count = req.url_params.get_list("count");
os << "The key 'count' contains " << count.size() << " value(s).\n";
for(const auto& countVal : count) {
os << " - " << countVal << '\n';
}
return crow::response{
os.str()};
});
app.port(18080).multithreaded().run();
}
curl库
#include <stdio.h>
#include <curl/curl.h>
bool getUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL) // 返回结果用文件存储
return false;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: Agent-007");
curl = curl_easy_init(); // 初始化
if (curl)
{
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");// 代理
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);// 改协议头
curl_easy_setopt(curl, CURLOPT_URL,"http://www.baidu.com");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); //将返回的http头输出到fp指向的文件
curl_easy_setopt(curl, CURLOPT_HEADERDATA, fp); //将返回的html主体数据输出到fp指向的文件
res = curl_easy_perform(curl); // 执行
if (res != 0) {
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
}
bool postUrl(char *filename)
{
CURL *curl;
CURLcode res;
FILE *fp;
if ((fp = fopen(filename, "w")) == NULL)
return false;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "&logintype=uid&u=xieyan&psw=xxx86"); // 指定post内容
//curl_easy_setopt(curl, CURLOPT_PROXY, "10.99.60.201:8080");
curl_easy_setopt(curl, CURLOPT_URL, " http://mail.sina.com.cn/cgi-bin/login.cgi "); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fclose(fp);
return true;
}
int main(void)
{
getUrl("/tmp/get.html");
postUrl("/tmp/post.html");
}
struct curl_httppost* post;
struct curl_httpposr* last;
curl_formadd(&post,&last,CURLFROM_COPYNAME,"image_file",CURLFROM_BUFFER,"data"
,CURLFROM_BUFFERPTR,fram_encoder_str.c_str(),CURLFROM_BUFFERLENGTH,
fram_encoder.length(),CURLFROM_END);
curl_formadd(&post,&last,CURLFROM_COPYNAME,"json_str",CURLFROM_BUFFER
,CURLFROM_COPYCONTENTS,json.dump().c_str(),CURLFROM_END);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_data_json);
size_t write_data_json(void* ptr,size_t size ,size_t nmeb,void* stream)
{
std::string data((const char*) ptr,(size_t)size*nmeb);
*(std::stringsream *)stream<<data<<endl;
return size*nmeb;
}
三级目录
边栏推荐
- Towhee weekly model
- Golang jwt跨域鉴权
- 记一次TCP丢包带来的重大性能问题
- Redis (IX) - redis distributed lock
- 科目三: 济南章丘三号线
- JS to realize page Jump and parameter acquisition and loading
- CloudCompare&PCL 匹配点中值(或标准差)距离抑制
- Article main content extraction software [based on NLP technology]
- Principle of bean validation --07
- 三种常见的移动底盘运动学模型分析
猜你喜欢

Parallels Desktop启动虚拟机“操作失败”问题解决

2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units

手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践

Big talk · book sharing | lean product development: principles, methods and Implementation

Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice

Session&Cookie&token

Redis面试题(2022)

Towhee weekly model

452 pages, 130000 words, the overall solution of modern smart Township Xueliang project 2022 Edition

Redis (IX) - redis distributed lock
随机推荐
What is the principle difference between lateinit and lazy in kotlin
Cool Lehman VR panorama paves the way for you to start a business
Detailed analysis of trajectory generation tool in psins toolbox
webpack打包vue项目添加混淆方式,解决缓存问题
知识图谱:知识表示
E-commerce system combined with commodity spike activities, VR panorama continues to bring benefits
技术分享 | 需要小心配置的 gtid_mode
Specified interval inversion in the linked list
物联网智能家居项目---智能卧室
scala 不可变Map 、 可变Map 、Map转换为其他数据类型
Daily question 1: delete continuous nodes with a total value of zero from the linked list
Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!
H. 265 web player easyplayer's method of opening video to the public
An online duplicate of a hidden bug
leetcode每日一练:将句子排序
搜索旋转排序数组
Golang sends email to the mail Library
Is VR panorama just needed now? After reading it, you will understand
11.zuul路由网关
Greenplum [deployment 08] database small version upgrade process and problem handling error: open-source-greenplum-db-6 conflicts with