如何通过卡萨布兰卡检索响应头
How to retrieve response header via casablanca?
wchar_t token[50];
http_client client(L"https://example.com/dir/");
http_request request;
std::stringstream ReqBody;
std::string ReqBodyS;
ReqBody << "login=" << TB1T << "&pass=" << TB2T;
ReqBodyS = ReqBody.str();
request.set_body(ReqBodyS);
request.set_method(methods::POST);
request.headers().set_content_type(U("application/x-www-form-urlencoded"));
client.request(request).then([](http_response response) {
if (response.status_code() == status_codes::OK)
{
//
}
});
反应像
Connection: keep-alive
Content-type: text/html
SomeHeader: something here
我如何添加文本从标题与名称SomeHeader令牌?我想从someheader
这是一个旧的帖子,但我会给你一些帮助,我假设你已经解决了你的问题很久以前,但如果没有,或者如果有人得到同样的问题,这里一些解释。
如果你想用c++ Rest SDK aka Casablanca获取请求头:
你有你的令牌头的属性,按照惯例它是"授权"。要获取令牌,只是一个基本的例子,您只需要这样做:
auto authorization = utility::conversions::to_utf8string(request.headers()[header_names::authorization]);
我为变量的类型写了auto,但它也可以是std::string。
现在,如果你想在你的请求中添加一个头,比如"授权",你可以把它写成另一个headers参数。下面是一个例子:
http_response response;
response.set_status_code(200);
response.headers().add(U("Authorization"), U("your token"));
希望它能帮助你和其他有类似问题的人。
相关文章:
- 使用VerQueryValue检索应用程序的文件描述
- 是否可以从格式字符串中检索"width"
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 如何在QByteArray中放置和检索位字段而不会感到痛苦?
- 如何在Qt中从数据库中检索二进制数据?
- C++ 信号和插槽不工作:插槽不响应事件
- NodeJs 服务器充斥着 UDP 广播,不发送响应
- 如何从C++代码中检索 QML 的文本字段中的文本?
- C++关于ENUM的问题。我得到的响应比枚举列表大
- 从 opencv c++ 中的矢量中检索固定的帧数
- 如何在不等待检索的情况下获取C++中的内存位置?
- 如何在 QTreeWidget 中检索特定项目的 mimeData?
- C++从字符串中检索几行
- 应用程序在打开的简历中捕获视频后没有响应
- 使用 cpprest (Casablanca) 返回 PDF 响应
- 在数据库中插入和检索矩阵
- 如何发送http请求并检索json响应C++Boost
- 正在从cpp中的curl检索响应文本
- 如何通过卡萨布兰卡检索响应头