I use WWW library for Unity in C#. When i call function Send from main thread it's ok.
PostWorker pw = new PostWorker();
API.instance.StartCoroutine(pw.Send(url, postParams));
But when i try make it from PostWorker
API.instance.StartCoroutine(Send(url, postParams));
it's not work with such error:
StartCoroutine_Auto can only be called from the main thread.
If I call the function without Coroutine
it doesn't work and not enter in Send
.
private IEnumerator Send(string path, Dictionary<string, string> postData)
{
WWWForm form = new WWWForm();
if (postData != null && postData.Any())
{
foreach (var item in postData)
{
form.AddField(item.Key, item.Value);
}
}
WWW www = new WWW(path, form);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
Debug.Log(www.text);
}
else
{
Debug.Log(www.error);
}
}
So, how can i execute http request from not-main thread?