Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

WWW Instance url to relative path. Is it possible?

Discussion in 'Editor & General Support' started by fernando24691, Jan 18, 2011.

  1. fernando24691

    fernando24691

    Joined:
    Jun 30, 2010
    Posts:
    20
    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!
     
  2. Tempest

    Tempest

    Joined:
    Dec 10, 2008
    Posts:
    1,286
    Yes, using "http://localhost/" will work.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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
     
  4. Tempest

    Tempest

    Joined:
    Dec 10, 2008
    Posts:
    1,286
    Correct. He mentioned localhost, so that's why my answer was such.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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
     
  6. jaxx0rr

    jaxx0rr

    Joined:
    Aug 25, 2013
    Posts:
    23
    Code (csharp):
    1. function Start () {
    2.     //print("platform:"+Application.platform);
    3.     //print("path:"+Application.dataPath);
    4.     if (Application.platform == RuntimePlatform.WindowsEditor){
    5.         urlPrefix = "file://"+Application.dataPath+"/../../exe/Music/"; // we get back from AppName/Assets
    6.     }
    7.     if (Application.platform == RuntimePlatform.WindowsPlayer){
    8.         //(Music folder should be next to AppName_Data folder, if its inside it, it will get deleted on build)
    9.         //urlPrefix = "file://e:/!save/Unity/exe/Music/"; // absolute path works but useless
    10.         //urlPrefix = "/../Music/";// does not work
    11.         //urlPrefix = "../Music/";// does not work either
    12.         //urlPrefix = "file:///../Music/";// does not work either
    13.         //urlPrefix = "file://../Music/";// does not work either
    14.         urlPrefix = "file://"+Application.dataPath+"/../Music/"; //relative path that works!
    15.     }
    16.     if (Application.platform == RuntimePlatform.WindowsWebPlayer){
    17.         urlPrefix = "http://www.blabla.com/music/";
    18.     }
    19.  
    20. }
     
    Last edited: Oct 9, 2013