0
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)
        {
            //
        }
    });

Response like

Connection: keep-alive
Content-type: text/html
SomeHeader: something here

How can i add text from header with name SomeHeader to Token? I want get in token text from someheader

own2pwn
  • 311
  • 2
  • 7

1 Answers1

0

It's an old post, but i will give you some help, i presume you already resolved your problem long time ago, but if not, or if someone got the same problem, here some explanation.

If you want to get the header of a request with C++ Rest SDK aka Casablanca:

You got an attribute of you header with your token, by convention it's "authorization". For getting your token, just a basic example, you just have to do this:

auto authorization = utility::conversions::to_utf8string(request.headers()[header_names::authorization]);

I wrote auto for the type of your variable, but it can be std::string .

Now if you want to add an header to your request, like "authorization" for exemple, you can write it like another headers parameter. Here an example:

http_response response;
response.set_status_code(200);
response.headers().add(U("Authorization"), U("your token"));

Hope it can help you and other folks with similar issues.

Eric
  • 11
  • 5