0

here is my post request to server:

public WWW POST(string url, string post) 
{ 
    var www = new WWW(url, Encoding.UTF8.GetBytes(post));

    StartCoroutine(WaitForRequest(www));
    while (!www.isDone && www.error == null)
    {
        Console.Write("downloading...");
        Thread.Sleep(1000);
    }
    return www;
}

private IEnumerator WaitForRequest(WWW www)
{
    while (!www.isDone && www.error == null) { yield return new WaitForSeconds(0.1f);}

    // check for errors
    if (www.error != null)
    {
        Debug.Log("WWW Error: " + www.error);
    }
}

it works fine in Unity Editor, but it freeze to unlimited loop in Web Player Build version. Does anybody know why?

animekun
  • 1,789
  • 4
  • 28
  • 45
  • 1
    If `www.error` is not null, the loop will continue forever. Is it possible you're running afoul of the [cross-domain security sandbox](https://docs.unity3d.com/Documentation/Manual/SecuritySandbox.html)? – rutter May 02 '14 at 19:33
  • the while loop is fine as the isDone is part of an and condition. Can you use Thread.Sleep and Console.Write in the webplayer? – normower May 04 '14 at 00:52

1 Answers1

0

okay, the problem was in coroutines

    public IEnumerator LoginFinished(string message)
    {
        string url = "URL";
        Console.Write("Post on: " + url);
        var response = _httpServer.POST(url, message.Substring(message.IndexOf('?') + 1));
        while ( !response.isDone && response.error == null )
        {
            yield return new WaitForEndOfFrame();
        }
        Console.Write("response: " + Zlib.Unzip(response.bytes));
    }


    public WWW POST(string url, string post)
    {
        var www = new WWW(url, Encoding.UTF8.GetBytes(post));
        StartCoroutine(WaitForRequest(www));
        return www;
    }

    private IEnumerator WaitForRequest(WWW www)
    {
        yield return www;

        if (www.error != null)
        {
            Debug.Log("WWW Error: " + www.error);
        }
    }

if i do

StartCoroutine(LoginFinished("authdata"));

it works just fine.

animekun
  • 1,789
  • 4
  • 28
  • 45