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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top