I have a Application in which i am hitting my backend API which Gives CSRF-TOKEN in Set-Cookie Header and I need to send it to the Server as X-CSRF-TOKEN
For That i am reading the Set-Cookie with
Dictionary<string, string> headers = request.GetResponseHeaders();
string tokenHeader = headers.GetValueOrDefault("Set-Cookie");
OR
string tokenHeader = request.GetResponseHeader("Set-Cookie");
and Processing as
if (!string.IsNullOrEmpty(tokenHeader))
{
string[] cookieArray = tokenHeader.Split(',');
foreach (string cookiePart in cookieArray)
{
string[] cookieParts = cookiePart.Split(';');
foreach (string part in cookieParts)
{
if (part.Contains("CSRF-TOKEN"))
{
string[] keyValue = part.Split('=');
if (keyValue.Length == 2)
{
PlayerPrefs.SetString(Token.CsrfToken.ToString(), keyValue[1]);
Debug.Log("CSRF-TOKEN saved to PlayerPrefs." + keyValue[1]);
}
}
if (part.Contains("SESSION"))
{
string[] keyValue = part.Split('=');
if (keyValue.Length == 2)
{
PlayerPrefs.SetString(Token.Session.ToString(), keyValue[1]);
Debug.Log("SESSION saved to PlayerPrefs." + keyValue[1]);
}
}
if (part.Contains("remember-me"))
{
string[] keyValue = part.Split('=');
if (keyValue.Length == 2)
{
PlayerPrefs.SetString(Token.RememberMe.ToString(), keyValue[1]);
Debug.Log("remember-me saved to PlayerPrefs." + keyValue[1]);
}
}
}
Now this Code works Perfectly in
.dmg and .exe builds but in WebGl Builds are not Working
Can Anyone Help me with that
#Urgent