- Home /
Coroutine for WWW call not resuming
Hi!
I want to make an API call using the WWW class. In order to do this I start a coroutine, but a lot of the times it isn't resumed, it works half of the time.
I start the coroutine like this:
StartCoroutine(APIcalls.Instance.CreateMatch(serverName));
And the function the coroutine is calling looks like this:
public IEnumerator CreateMatch(string serverName){
Debug.Log ("Sending data to API...");
WWWForm form = new WWWForm ();
form.AddField("name",serverName);
WWW postURL = new WWW(GameSettings.ApiURL+"/api/matches", form);
yield return postURL;
Debug.Log ("POST call complete?");
if (!string.IsNullOrEmpty(postURL.text)) {
var match = JSON.Parse (postURL.text);
Debug.Log ("Created match with id: " + match ["match_id"]);
}
else {
Debug.Log ("Error: "+postURL.error);
}
}
So half of the time I don't even get the log "POST call complete?", like the coroutine never resumes after the yield.
The call reaches the API route, I can see things happening in my api, but the coroutines is not resumed.
Can you see what might be causing this error?
Thanks for the help!
Your answer
Follow this Question
Related Questions
Returning from Coroutine stops the Update() method. 0 Answers
Use the data received from WWW in UI 1 Answer
Unable to call external API (IBM Watson) via HTTP request? 1 Answer
Calling API via proxy 0 Answers
How to yiled a try/catch block? 2 Answers