- Home /
WWW class on WebGL: URL is wrong
Hi there, I've googled a lot but I'm unable to find any info in this subject, since I don't really know what to search, because this problem is a little curious.
So, basically I'm using the WWW Class for Authenticating on my new game, everything works right inside the Editor, but once you compile to WebGL and upload the build you can clearly see something's wrong.
This is the code I'm using to check if the Auth Service is reachable:
WWW www = new WWW("http://devmidgard.com/auth");
while (!www.isDone)
{
yield return null;
}
if (www.error == null)
{
Debug.Log("Ping Done, Auth Service reachable.");
isConnected = true;
}
else
{
// Some error here
}
Everything should be right, it works in Editor and it should be fine.
But I was surprised when I checked Chrome's Console for errors, since the try to ping the Auth Service failed, and this is what I got:
GET http://devmidgard.com/games/hockey/devmidgard.com/auth 404 (Not Found)
http://devmidgard.com/games/hockey/ is the place where you can play the game.
While the later part (devmidgard.com/auth) is where the Auth Service is located (all the php scripts that make contact with a database, and return values, etc).
The problem is, as you can see, the WWW Class joined the working directory (http://devmidgard.com/games/hockey/) with the Request URL (http://devmidgard.com/auth).
Is there something I might be doing wrong? I don't really know how to solve this issue, but it is critical. If I'm unable to contact my Auth Server, then I'm unable to load the player's progress, etc.
Answer by illa3d · Aug 18, 2016 at 03:23 PM
I'm getting the same issue on both Chrome and Firefox with the newest Unity 5.4.0. I noticed that error while still on 5.3.3.
In my eyes this is a bug and is reported.
For the time being the only solution is to have the index.html in the root, or every WWW asset or service you need in the subfolder to the root index is in. That way you can just add incrementally paths to the "home app path". In your case that would be devmidgard.com/games/hockey/auth.
Hey, I ended up upgrading to the latest version of Unity back then and it worked. I really don't know what was wrong.
I haven't checked with Unity 5.4.0 but I will try it out later, it might have appeared again.
Thanks for your time
Your answer
Follow this Question
Related Questions
How to use POST service using www class? 0 Answers
Use the data received from WWW in UI 1 Answer
WWW Class is acting up 1 Answer
How to read and rewrite text files on a local host with WebGL? 0 Answers