【发布时间】:2018-01-10 02:59:01
【问题描述】:
为了让我的桌面应用程序访问我的谷歌驱动器,我使用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”
我的代码中有一些不正确的传输编码,我无法弄清楚。我错过了什么?
编辑:Postman 中的相同请求工作正常(有或没有分块传输编码)。
谢谢, 苏里亚
【问题讨论】:
标签: c++ c++11 google-drive-api poco poco-libraries