c++ - 如何从标头中检索不记名令牌(rest sdk)
问题描述
我曾多次使用 REST SDK。我想Bearer
使用 C++ 从响应标头中检索令牌。
我试过这个:
CMyClass::SomeMethod(const web::http::http_request& Request)
{
const web::http::http_headers& headers = Request.headers();
web::http::http_headers::const_iterator it = headers.find(web::http::header_names::authorization);
if (it != headers.end())
{
std::cout << "+++\t" << it->first.c_str() << "\t" << it->second.c_str() << std::endl;
}
}
但我只得到这个:
这告诉我我做错了什么。
那么,如何Bearer
从标头中检索令牌web::http::http_request
?
解决方案
您看到的输出意味着您没有将char*
字符串指针传递给std::cout
.
假设您使用的是Microsoft 的 REST SDK(您没有说),它的web::http::http_headers
类包含utility::string_t
值,并且在 Windows 上utility::string_t
定义std::wstring
(尽管文档说),std::string
不像您期望的那样。
这意味着您将wchar_t*
字符串指针传递给std:::cout
,它没有operator<<
for wchar_t*
,但确实有一个 for void*
,因此您会看到输出。
您需要std::wcout
改用,或者在打印之前将std::wstring
数据转换为。std::string
推荐阅读
- firebase-realtime-database - 如果用户关闭窗口或选项卡,如何保存对 firebase 文档的更改
- java - 我想根据从微调器中选择的值从特定的数组列表中获取元素
- react-native - undefined 不是对象(评估 '_expo.Permission.askAsync')
- python - 用一行在python中获取数组的元素
- php - 如何访问另一个数组中的数组
- git - 当工作分支不使用子模块时,如何合并来自包含子模块的 git 分支的更改
- javascript - 如何使用 JavaScript+React 处理条件运算符?
- javascript - 如何将两个 JavaScript 文件链接在一起?没有 HTML
- numpy - Miniconda 是否也受益于 numpy 的 MKL 优化?
- r - 如何在使用 rvest 和 stringr 从 R 中的网站抓取数据时遍历大量 ID?