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的header中的文本添加到Token?我想从某个标头获取标记文本
发布于 2019-11-19 06:51:30
这是一个古老的帖子,但我会给你一些帮助,我假设你已经解决了你的问题很久了,但如果没有,或者如果有人遇到了同样的问题,这里有一些解释。
如果你想用C++ Rest SDK获取请求头,也就是卡萨布兰卡:
你用你的令牌获得了你的头的一个属性,按照惯例它是“授权”。为了获得令牌,这只是一个基本的示例,您只需执行以下操作:
auto authorization = utility::conversions::to_utf8string(request.headers()[header_names::authorization]);我为你的变量类型写了auto,但它可以是std::string。
现在,如果你想给你的请求添加一个头部,比如"authorization“,你可以像另一个headers参数一样编写它。下面是一个示例:
http_response response;
response.set_status_code(200);
response.headers().add(U("Authorization"), U("your token"));希望它能帮助你和其他有类似问题的人。
https://stackoverflow.com/questions/30577012
复制相似问题