编辑:有关如何解决此问题的答案,请参见下面的我的帖子。
我正在构建一个客户端应用程序,它将在用户保管箱应用程序文件夹中存储一些数据。因此,当前我使用的是隐式授权,它会将用户重定向到给定的重定向uri,并使用网址中#号后面传递的参数
示例:
localhost:1666 / Dropbox#access_token = ...&token_type = .......
通过localhost url创建一个HTTP侦听器,它可以检测到请求,但是#之后的所有内容都将被忽略,并且不会作为请求的一部分传递。有没有办法在#之后捕获数据,或者是否有其他库允许我这样做?
我正在使用cpprestsdk https://github.com/microsoft/cpprestsdk
web::http::experimental::listener::http_listener* l = new web::http::experimental::listener::http_listener(m_authConfig.redirect_uri());
l->support([this](web::http::http_request request) -> void
{
auto uri = request.request_uri();
auto requestPath = web::uri::split_path(uri.path());
auto querryObjects = web::uri::split_query(uri.query());
auto s = uri.fragment();
if (request.request_uri().path() == U("/Dropbox")) && request.request_uri().query() != U(""))
{
request.reply(web::http::status_codes::OK, U("ok.") + uri.query());
}
else
{
request.reply(web::http::status_codes::OK, U("error.") + uri.query());
}
});
l->open().wait();
谢谢!
答案 0 :(得分:0)
因此,在进行了一些研究之后,结果发现大多数浏览器中都不会发送回#(片段),因此为了获取数据,我返回了以下Java脚本脚本:
<script> window.location.replace([location.protocol, '//', location.host, location.pathname, '?', location.hash.substring(1,location.hash.length )].join(''));</script>
这会将哈希部分转换为查询字符串,并将其重定向到用户,以便侦听器检测到它。