I am working with publicly available site https://studia3.elka.pw.edu.pl using Flurl.Http. The _restClient
is obtained from PerBaseUrlFlurlClientFactory
with address https://studia3.elka.pw.edu.pl/pl/
With certain request it should send me back a cookie for further use. I receive the cookie in the response (it is in the headers section) but the cookie is not present in my client's cookie dictionary (where I think it should appear after getting a response)
My code for making the request and reading the response is following:
private const string StudiaIdCookieName = "STUDIA_SID";
var cook = new Cookie(name: "STUDIA_COOKIES", value: "YES&", path: "/", domain: ".studia3.elka.pw.edu.pl");
var unauthenticatedCookiesRequest = _restClient.Request().WithCookie(cook);
var unauthenticatedCookiesResponse = await unauthenticatedCookiesRequest.SendAsync(verb: HttpMethod.Get);
if (!_restClient.Cookies.ContainsKey(key: StudiaIdCookieName))
throw new Exception(message: "Failed to get unauthenticated cookie from Studia");
var authenticateCookieRequest = _restClient.Request().AppendPathSegment(segment: LdapPathSegment);
var authenticateCookieResponse = authenticateCookieRequest.PostUrlEncodedAsync(data:
new { studia_login = username, studia_passwd = password });
The problem is with
if (!_restClient.Cookies.ContainsKey(key: StudiaIdCookieName))
throw new Exception(message: "Failed to get unauthenticated cookie from Studia");
as _restClient.Cookies only contains the cookie i manually set up and not the one from the response (the response cookie is called STUDIA_SID and it is present under headers section when i browse the response in debugger).
My question is: should the Cookies property reflect the changes of making request? If not, should I manually check the headers and extract cookie from there?