WWW Request runs in Editor but not in Webplayer

As the title says, I’m sending an WWW request to my webserver that has a crossdomain policy and everything working correctly. As also mentioned, everything works perfectly fine without and errors or anything in the Editor.

But when trying to run the same exact game in a Webplayer build, it simply just freezes, not even my Try-Catch fires.

This is the part, where I try to fire the WWW Request code:

if(GUILayout.Button("Create Channel", GUI.skin.button)) {
	try {
		int channelID = int.Parse(DataHandler.self.CreateChannelID(ChannelName));
		if(channelID != 0) {
			Message = "Channel Created!";
		} else {
			Message = "Channel Name already exist!";
		}
	} catch(UnityException err) {
		Message = err.Message;
	}
}

And this is the part, where the 'behind the scenes happen, A.K.A the WWW Request. Note that I have edited the urlRequest for this question, for security purposes of mine, It’s tested in browser and works there aswell.

public string CreateChannelID(string ChannelName) {
	string urlRequest = "http://mywebsite.com/game/AddChannel.aspx?ChannelName=" + ChannelName;
	
	WWW request = new WWW(urlRequest);
	StartCoroutine(YieldRequest(request));
	
	while(!request.isDone) {}
	
	return stripString(request.text);
}

private IEnumerator YieldRequest(WWW request) {
	yield return request;
}

Line 7 does a busy-wait for the request to complete. Depending on the WWW implementation (which varies between platforms), the request may or may not be able to complete in the background - on some platforms it requires your code to return control to Unity. So you need to avoid busy loops like that - they are really bad practice anyway.

The easiest way to resolve this is probably to move all of the response to the button getting pressed into a coroutine. Then that coroutine can yield waiting for the request to complete, without blocking OnGUI. Something like this:

    if(GUILayout.Button("Create Channel", GUI.skin.button)) {
        StartCoroutine(DoCreateChannel());
    }

...

private IEnumerator DoCreateChannel() {
    string urlRequest = "http://mywebsite.com/game/AddChannel.aspx?ChannelName=" + ChannelName;

    WWW request = new WWW(urlRequest);
    yield return request;

    string result = stripString(request.text);

    int channelID = int.Parse(result);

    if(channelID != 0) {
        Message = "Channel Created!";
    } else {
        Message = "Channel Name already exist!";
    }
}

If you need some of the processing to be encapsulated elsewhere then you can do that but it’s best if the WWW request itself is handled here. Otherwise you end up needing to chain coroutines together, and you quickly reach a point where pretty much every function involved has to be a coroutine, and it’s all badly coupled.