Poco HTTPSClientSession with google drive api
Poco HTTPSClientSession with google drive api
为了让我的桌面应用程序访问我的谷歌云端硬盘,我正在使用 Poco 进行身份验证和查询。请求访问令牌时,我遇到了Poco::Net::HTTPSClientSession
问题。我的代码如下。
namespace net = Poco::Net;
net::Context::Ptr ctx =
new net::Context(net::Context::CLIENT_USE, "", net::Context::VerificationMode::VERIFY_NONE);
net::HTTPSClientSession client("accounts.google.com", net::HTTPSClientSession::HTTPS_PORT, ctx);
net::HTTPRequest req(net::HTTPRequest::HTTP_POST, "/o/oauth2/token", net::HTTPMessage::HTTP_1_1);
net::HTMLForm form;
form.add("code", accessCode);
form.add("client_secret", client_secret);
form.add("client_id", client_id);
form.add("grant_type", "authorization_code");
form.add("redirect_uri", redirect_uri);
form.prepareSubmit(req);
// req.setChunkedTransferEncoding(true);
form.write(std::cout);
std::cout << std::endl;
client.sendRequest(req);
req.write(std::cout);
std::cout << "Method: " << req.getMethod() << std::endl;
net::HTTPResponse resp;
auto&& is = client.receiveResponse(resp);
std::copy(
std::istream_iterator<char>(is), std::istream_iterator<char>(), std::ostream_iterator<char>(std::cout));
std::cout << std::endl;
我收到上述代码超时异常。如果我打开分块传输编码,我会收到来自谷歌的错误
"缺少必需参数:grant_type">
我的代码中的传输编码存在一些错误,我无法弄清楚。我错过了什么?
编辑:邮递员中的相同请求工作正常(有或没有分块传输编码(。
谢谢苏里亚
回答我自己的问题。
我没有将表单数据写入请求的正文中,这会带来问题。像这样更改了代码
auto&& strm = client.sendRequest(req);
form.write(strm);
现在它起作用了。
相关文章:
- 用于访问容器<T>数据成员的正确 API
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++MySQL C api用户输入行
- 如何使用 AWS Transcribe C++ API 中的'StartTranscriptionJobRequest'?
- 将std::string传递给WriteConsole API
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在gtest.中使用fff.h模拟系统API
- 有没有任务栏API可以立即应用注册表更改
- C++win32 API创建多个类似视口的窗口
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 如何将真正的字符串从python c-api转换为python脚本
- 使用Qt框架在c ++类中创建API调用
- Libreoffice API (UNO):需要更改用户的 xTextField 文本
- 使用 WIN32 API (C/C++) 对特定树视图项进行着色
- 使用 Python Extension API 包装复杂C++类
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- 第三方 API 中的编译错误 - Visual Studio
- Poco HTTPSClientSession with google drive api
- 适用于 C 或 C++ 的 Google Drive API
- c++/qt中google-drive的api和工具