首页 > 解决方案 > 使用 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 发送文件的正确方法是什么?

标签: c++rest

解决方案


推荐阅读