cpprestsdk http_listener忽略 # 之后的所有内容

cpprestsdk http_listener ignoring everything after #

本文关键字:之后 http listener 忽略 cpprestsdk      更新时间:2023-10-16

>编辑:请参阅我下面的帖子,了解如何解决此问题。

我正在构建一个客户端应用程序,该应用程序将在用户保管箱应用程序文件夹中存储一些数据。所以目前我正在使用隐式授权,它将用户重定向到给定的重定向 uri,并在 url 中的 # 之后传递参数

例:

本地主机:1666/保管箱#access_token=...&token_type=...

通过本地主机 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 queryObjects = 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();

谢谢!

所以经过一番研究,事实证明#(片段(在大多数浏览器中都不会发回,所以为了能够获取数据,我返回以下java脚本脚本:

<script> window.location.replace([location.protocol, '//', location.host, location.pathname, '?', location.hash.substring(1,location.hash.length )].join(''));</script>

这会将哈希部分转换为查询字符串,并将其重定向到用户,以便侦听器检测到它。