- Home /
What to do after setting up crossdomain.xml
My game needs to get a string from a xml doc on my website. This all worked fine when the game was in standalone, but due to security reasons Webplayers are a bit more complicated.
I've set up my crossdomain.xml at my websites root folder and everything is working out fine. But here is the problem. I know how to get a string from xml in standalone from website. I know how to set up the crossdomain. But I don't know how to get the value after setting up the domain.
Either I'm really stupid right now, or there is something missing in the docs.
Should the string I want to get be in the crossdomain file? Or what am I supposed to do now?
As it is now I have a crossdomain file looking like this:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"secure="false"/>
</cross-domain-policy>
at: http://WEBSITE.com/crossdomain.xml
and the string at: http://WEBSITE.com/MasterIP.xml
How should I go about getting the string now?
My old code did this, which works on standalone:
IEnumerator GETIP(){
WWW www = new WWW("http://WEBSITE.com/MasterIP.xml");
while(!www.isDone)
{
yield return new WaitForSeconds(0.1f);
}
string wwwtext = ASCIIEncoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8,Encoding.ASCII,www.bytes));
Debug.Log("new xmldoc");
XmlDocument result = new XmlDocument();
Debug.Log("loadxml");
try
{
result.LoadXml(wwwtext);
}
catch{}
Debug.Log(result.InnerText.ToString());
masterIP = result.InnerText.ToString();
return false;
}
It returns the IP without a problem. But when using Webplayer and crossdomain, how should I go about to fetch the IP?
First time using xml and WWW in unity so sorry if the answer is obvious.
Answer by Bunny83 · Dec 04, 2014 at 12:47 PM
You don't need to do anything. When Unity detects that you try to access a domain different than your hosting domain it will automatically request the crossdomain.xml file on that foreign server. If the crossdomain is missing, somehow not formatted right or doesn't allow access your request will fail with a security exception. Otherwise you will get the same result as in a standalong build.
If the file you want to access is hosted on the same domain as your webplayer there's no need for a crossdomain policy since you don't have "crossing domains". The webplayer can access anything on the domain it's hosted on. Of course only if the resource is actually reachable from the internet. For this you should check your server configuration (htaccess, ...)
Ah okay then I understand. Well since I'm currently testing from the editor I'm not on the same domain, that's why I thought I needed it.
This gave me a lot more clarity then the Unity docs did, thanks a lot!
(Just tested it again and it works now, had a typo in the crossdomain file -.-).
The crossdomain.xml parser is quite "sensitive". It should be encoded in ASCII. So if saved with norepad make sure you don't save as utf8. Actually utf8 and ASCII would be compatible, however notepad adds a BO$$anonymous$$ at the start which usually screws up the parser. You might want to have a look at the SecuritySandbox page.
Your answer
Follow this Question
Related Questions
web page html parsing 1 Answer
Posting raw XML data to web - no parameter name 2 Answers
Returning correct result after uploading 0 Answers
WebGL WWW and Localhost CORS 0 Answers
How to read xml file using javascript? 0 Answers