WWW.text is allways empty

I’m trying to create a simple login system using php/json.
But it fails at the www.text

Here I add the listener to my button

button.onClick.AddListener (LoginUser);
void LoginUser()
    {
        StartCoroutine (CheckLogin());
    }

Login code

IEnumerator CheckLogin()
    {
        //Saving user details
        if (saveDetails.isOn)
        {
            PlayerPrefs.SetString ("username", inputUsername.text);
            PlayerPrefs.SetString ("password", inputPassword.text);
            PlayerPrefs.Save ();
        }

        //Create a new form connection
        WWWForm loginForm = new WWWForm ();
        //Form values
        loginForm.AddField ("username", inputUsername.text);
        loginForm.AddField ("password", inputPassword.text);
        //Sync URL with Form
        var headers = loginForm.headers;
        headers ["content-type"] = "application/json";
        WWW www = new WWW(WWWUrl.LOGIN_URL, loginForm.data, headers);
        yield return www;

        Debug.Log (WWWUrl.LOGIN_URL + " : status " + www.uploadProgress);

        if (!string.IsNullOrEmpty(www.error) && www.isDone)
        {
            Debug.Log("Trying to login! " + www.text);
        }
        else
        {
            errorPanel.gameObject.SetActive(true);
            errorText.text = www.error;

            Debug.Log("WWW Error: " + www.error);
        }
    }

This is empty even when I load the url in the browser I get a valid Json

Debug.Log("Trying to login! " + www.text);

I have added hhtps:// infront of the url.

What am I doing wrong?

You don’t wait to it to finish. Just add a yield return new WaitForSeconds(1f); before it and it should work.

Right before I check the text? What is the yield return www doing then?

It’s returning it immediately. Give it a sec before that and let me know.

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.

Aah yes that makes sense. I will try this tonight.