Open Intagrit-F opened 5 years ago
Do you reuse HttpClient or create new instances for each request. What I've found it this: https://github.com/Microsoft/dotnet/issues/395
Not sure this is related to what you are experiencing. If not, I would advise you to build the library from sources and investigate/debug why cookies are lost in .NET FX.
Thanks for the quick response. We are not creating new instances each time. We do have 2 instances of the ODataClient:
The AfterResponse of the first "Logon" request is used to fill the BeforeRequest of the 2nd "request" client.
` List
//Get CSRF token and SSO cookie of the response headers
settingsLogon.AfterResponse = (r) =>
{
ssocookies.AddRange(r.Headers.GetValues("Set-Cookie"));
settingsRequest.BeforeRequest = (f) =>
{
f.Headers.Accept.Clear();
f.Headers.Add("Accept", "application/json");
f.Headers.Add("X-CSRF-Token", r.Headers.GetValues("x-csrf-token").First());
foreach (String cookie in ssocookies)
{
if (cookie.Contains("SAP_SESSIONID_"))
{
f.Headers.Add("Cookie", cookie);
}
}
};
};`
@object With .Net core 2.1 we are able to add cookies to the request header. With .Net framework 4.7.2 it is not possible to add cookies to the request header
Version: Simple.OData.Client 5.6.2
Please have a look at the code below. (we also tried adding the cookie with f.Headers.TryAddWithoutValidation)
settingsRequest.BeforeRequest = (f) => { f.Headers.Accept.Clear(); f.Headers.Add("Cookie", "mySSOcookie"); f.Headers.Add("Accept", "application/json"); f.Headers.Add("X-CSRF-Token", r.Headers.GetValues("x-csrf-token").First()); };
cookie correctly added in .Net core:
cookie missing in .Net framework: