Open balamcsd opened 6 years ago
Anyone to help! urgent
If your server uses cookies to implement session tracking your client can examine the Set-Cookie response header and set the Cookie request header using cpprestsdk usual http_headers
mechanisms.
There do appear to currently be some platform inconsistencies and may be bugs in the handling of cookie headers. See https://github.com/Microsoft/cpprestsdk/search?q=cookie&type=Issues
Yes, i examined the response header and noticed the "Set-Cookie" and found JSESSIONID=25EFC1E34E649D5A0D9E9DC05FF06E57; Path=/; Secure I dont know how to fetch this jessionid from response header, so i can use it in request header I want the client to use the same SESSIONID for future requests. I tried below code, throws compile error
if(m_cookie != "") request.headers().add("Cookie", m_cookie);
m_cookie = response.headers()["set-cookie"];
Could you please help me with sample code
I found the answer Define one class level variable
utility::string_t m_szSessionToken = L"";
Wherever you are adding other request headers, add cookie header
if (!m_szSessionToken.empty())
req.headers().add(L"Cookie", m_szSessionToken);
Once you get response
auto headers = response.headers();
auto it = headers.find(U("Set-Cookie"));
if (it != headers.end()) {
m_szSessionToken = it->second;
}
Please note that m_szSessionToken will be set only once (after the first response) which we store it and add it to request headers (from the second request onwards)
This way client will contact with same jessionid for every call
Yes, that looks right, you are implementing the client-side contract for session-management cookies. Glad you got it working.
Thanks for giving right direction towards simple solution
Developed POC in CPP using cpprest to call rest services (HTTPS) The communication followed is JSON - POST method, using basic authentication. Please suggest how to make it session aware: (ie) The client has to exchange HTTP Session ID via standard HTTP protocol
Similar to cookiecontainer in C#
Below code works, but does not have session management