I tried addind it right before the yield return www
,also before Debug.Log("Trying to login! " + www.text);
I even tried to yield it for 5sec.
My log just gives me
EDIT:
I just found out if I enter my API in webbrowser using http:// I get the json in my browser. and if I use https:// I get an error.
In unity when I use http:// I get www.error but empty, and when I use https:// I get www.text empty
EDIT2:
When I use the .NET version of http request it works just fine.
void LoginUser2()
{
// this is what we are sending
string post_data = "username=" + inputUsername.text + "&password=" + inputPassword.text;
// this is where we will send it
string uri = WWWUrl.LOGIN_URL;
// create a request
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri); request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
// turn our request string into a byte stream
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
// this is important - make sure you specify type this way
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// grab te response and print it out to the console along with the status code
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Debug.Log(new StreamReader(response.GetResponseStream()).ReadToEnd());
Debug.Log(response.StatusCode);
}
I believe you made an error in this code. The condition is TRUE when request is finished and there IS and error. Your then/else parts look the opposite When there is no error, www.error will be either null or empty. I suppose the ! at the beginning is a mistake.
And yield return www is a correct way to wait for finish, the code below that line will only execute after request is finished.