Вопрос

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