Hi there
I’d like to login to Web sytem like Django.
My Unity’s C# is this.
private IEnumerator RunLogin (string url)
{
// using POST
WWWForm form = new WWWForm ();
// csrf token
form.AddField ("csrfmiddlewaretoken", csrfToken);
string loginUsername = usernameField.text;
form.AddField ("username", loginUsername);
form.AddField ("password", passField.text);
// HEADER
Dictionary<string, string> headers = new Dictionary<string, string> ();
headers.Add ("Cookie", cookie_value);
byte[] rawData = form.data;
WWW www = new WWW (url, rawData, this.hsHeader);
yield return www;
if (www.error == null)
{
Debug.Log ("OK");
}
else
{
Debug.Log ("BAD");
}
}
And cookie_value and csrfToken is here
string cookie = "";
foreach (KeyValuePair<string, string> kv in www.responseHeaders)
{
if (kv.Key == "SET-COOKIE")
{
cookie = kv.Value;
}
}
cookie_value = cookie;
// json
JsonData data = JsonMapper.ToObject (jsonText);
bool isSuccess = false;
try
{
csrfToken = (string)data ["csrf_token"];
isSuccess = true;
Debug.Log (csrfToken);
}
But, I can’t login.
Error is this.
You are trying to load data from a www stream which had the following error when downloading.
403 FORBIDDEN
UnityEngine.WWW:get_text()
<RunLogin>c__Iterator8:MoveNext() (at Assets/Scripts/AvatarSystem/LoginSystem.cs:267)
Could you tell me how to login it?