WWW Instance url to relative path. Is it possible?

Hi all!

I’m working more frequently with the WWW class, and, since I’m hosting everything in the same server, I thought it would be faster to send WWW requests to “localhost” direction, and not to put the whole URL, making Unity to go out from the server and getting inside again. Is this possible?

Thanks!

Yes, using “http://localhost/” will work.

Relative path though would mean that no Http etc is present but a path in respect to the current src path.

the moment you add http is not relative anymore, its absolute and can require a crossdomain.xml to work any further

Correct. He mentioned localhost, so that’s why my answer was such.

even there it wouldn’t be required given he access it through http://localhost/ … already and not with file://
if he used file, localhost would indeed be required but then its also not relative anymore and has to comply to the security sandbox

function Start () {
	//print("platform:"+Application.platform);
	//print("path:"+Application.dataPath);
	if (Application.platform == RuntimePlatform.WindowsEditor){
		urlPrefix = "file://"+Application.dataPath+"/../../exe/Music/"; // we get back from AppName/Assets
	}
	if (Application.platform == RuntimePlatform.WindowsPlayer){
		//(Music folder should be next to AppName_Data folder, if its inside it, it will get deleted on build)
		//urlPrefix = "file://e:/!save/Unity/exe/Music/"; // absolute path works but useless
		//urlPrefix = "/../Music/";// does not work
		//urlPrefix = "../Music/";// does not work either
		//urlPrefix = "file:///../Music/";// does not work either
		//urlPrefix = "file://../Music/";// does not work either
		urlPrefix = "file://"+Application.dataPath+"/../Music/"; //relative path that works!
	}
	if (Application.platform == RuntimePlatform.WindowsWebPlayer){
		urlPrefix = "http://www.blabla.com/music/";
	}

}