c++ - 使用 C++ Rest SDK 上传文件
问题描述
使用 cURL 上传 CSV 文件的请求:
curl --location --request PUT 'http://localhost/store/apples/upload/' \
--header 'Accept: application/json' \
--form 'file=@"/home/user/Downloads/apples.csv"'
我正在尝试使用C++ Rest SDK实现一个 C++ 函数,该函数在功能上等同于上述请求:
void uploadCsvFile(const std::string& csv_file_path) const {
web::uri_builder builder(U("http://localhost/store/apples/upload/"));
http_client client(builder.to_string());
http_request req;
req.set_method(methods::PUT);
req.headers().add("Accept", "application/json");
// TODO: add the CSV file to the request
client.request(req).get();
}
但无法找出将文件包含在请求中的正确方法。
使用 C++ Rest SDK 发送文件的正确方法是什么?
解决方案
推荐阅读
- excel - 通过双击单元格从工作表调用宏
- java - 是否可以将方法调用转发到 java 中更专业的方法签名?
- python - AWS Lambda -- 无法为 SpaCy 导入 srsly.ujson.ujson
- java - 写一个下降幂的方法
- r - 无法使用自动绘图可视化“ts” - 错误:提供连续比例的离散值
- jestjs - 如何捕获或抑制来自 Jest 的拒绝网络请求?
- sql - 如何根据两个表中的两个键列将 SQL 查询写入联合/加入/或透视数据到来自两个相同表的列中?
- regex - 匹配需要模块的正则表达式?
- javascript - 我需要从数组中删除一个对象并根据条件显示一条消息
- python - reqPostions() 帮助断开 TWS / Interactive brokers / api