Unity HTTP call status

IEnumerator LoadData(){
        WWWForm form = new WWWForm();
        form.AddField ("id", USER_DATA.userid);
        WWW www = new WWW(URL.Url + "somepage.php", form);
        yield return www;
}

Hi. How can i check the status of the HTTP call? I mean how can i check if the HTTP call is:
-connecting
-connected
-connection failed

My only goal is to set a variable to 0 if the connection has failed.

if (the http call fails to connect){
    connection_established = 0;
}else{
    connection_established = 1;
}

Thanks for the attention.

I don’t think any of the http classes in Unity provide such a fine grained error control. HTTP calls open a connection, retrieve data and close the connection. If something goes wrong the HTTP protocol replies with a an error code (such as the popular 404).

Keeping a connection state in your code makes little sense because the connection is shut down as soon as you get a reply from the other side. If you check the WWWForm doc example you’ll see it provides a way for catching HTTP errors.

And if you want something more sophisticated check the UnityWebRequest class

1 Like

I already decided to check the first letter of the error, if there is no error the PHP file’s very first letter would be 0, else my client will throw an error. Thanks anyways. It’s too late to switch to UnityWebRequest… i already coded like 2k lines of code already :frowning: …thanks for the nice answer anyways.