如何使用 Casablanca 在 Dropbox API 中调用 /files (POST)
How to use Casablanca to call /files (POST) in Dropbox API
我正在使用 c++ 和 Casablanca 为我们的软件添加 Dropbox 功能。
我可以使用 OAuth 2 登录、获取元数据、打开文件并使用 files_put 成功保存文件。但是,我无法弄清楚如何使用/files(POST)保存文件。
我正在使用类似于下面的代码:(即我删除了一些函数来显示我最终得到的硬编码字符串)
{
using concurrency::streams::file_stream;
using concurrency::streams::basic_istream;
utility::string_t strURI = L"https://api-content.dropbox.com/1/files/dropbox/";
uri url(uri::encode_uri(strURI));
utility::string_t sb = url.to_string();
sb += L"?oauth_consumer_key=" + consumerKey + L"&";
sb += L"oauth_nonce=" + nonce + L"&";
sb += L"oauth_timestamp=" + timestamp + L"&";
sb += L"oauth_version=2.0";
sb += L"&access_token=" + accessToken;
sb += L"&file=" + strFilename; // I've tried with and without this line
return file_stream<unsigned char>::open_istream(strPath)
.then([sb, url, &bRet](task<basic_istream<unsigned char>> previousTask)
{
try
{
auto fileStream = previousTask.get();
//get the content length, used to set the Content-Length property
fileStream.seek(0, std::ios::end);
auto length = static_cast<size_t>(fileStream.tell());
fileStream.seek(0, 0);
// Make HTTP request with the file stream as the body.
http_request req;
http_client client(sb);
req.set_body(fileStream);
req.set_method(methods::POST);
return client.request(req)
.then([fileStream, &bRet](task<http_response> previousTask)
{
// Process response
}
}
};
}
我收到错误的请求响应。我认为问题是我没有正确给它文件名参数,但我不知道它应该去哪里。或者也许我完全错过了别的东西。
任何人都可以帮我澄清这一点吗?
附带说明一下,我认为您正在使用 OAuth 2,但您正在构建一个类似于 OAuth 1 签名的签名。我相信你可以这样做:
utility::string_t sb = url.to_string();
sb += L"?access_token=" + accessToken;
尽管将访问令牌放在身份验证标头中会稍微可取一些:Authorization: Bearer <access token>
.
我不是 100% 确定,但我相信/files (POST)
需要一个多部分形式编码的正文(因此文件名来自正文中的附件)。我不确定如何在卡萨布兰卡实现这一目标。但我真的会坚持/files_put
Dropbox 并仅对需要它的平台使用POST
请求(也许他们有更简单的接口来调用)。
相关文章:
- 如何使用curlpp通过POST方法上传文件和json数据
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 命名空间 pqxx 无法识别 - 将 libpqxx 添加到 Windows 上的 Visual Studio Post
- 如何使用boost/beast从HTTP POST请求中解析和提取有效负载?
- 如何使用 curl 将 POST 请求从 python 重写为 C++
- 从简单的 POST 请求中解析异常
- Visual Studio 2017 中的 cpprestapi 问题找不到 POST/GET 常量
- 使用 cpp-httplib 的 POST 请求
- POST Arduino 传感器值通过 Flask API 发送到本地 Sqlite db
- C++:如何通过 curl 调用使用 HTTP post 请求发送二进制数据(protobuf 数据)
- C++中的 cURL POST 请求
- C++ Schannel POST 400 错误代码错误请求
- 为什么 C++ 编译器在"c:program filesgnu emacsinclude"中查找包含文件?
- c++curl返回413请求实体过大,但是post大小远小于max大小
- HTTP POST 请求不允许我定义上下文类型
- 如何在c++中使用libcurl发送POST请求并接收它
- cpp libcurl 在 HTTP post 调用中发送 zip 文件,而不使用 multipart\form-da
- 使用 http post 在 FCM 中推送通知
- 我想将 POST 请求从 arduino 发送到 mysql 工作台并保存值
- 如何使用 Casablanca 在 Dropbox API 中调用 /files (POST)