Unity crossdomain.xml

时间:2014-08-26 21:57:30

标签: c# unity3d crossdomain.xml

我收到有关crossdomain.xml文件的错误消息,但我不知道如何解决它。我可以轻松地从网络浏览器访问网址。

来自网络浏览器

http://192.168.1.116:80/locJSON.txt

很好地给了我一大段JSON

来自网络浏览器

http://192.168.1.116/crossdomain.xml

给我回复跨域信息

<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
<allow-access-from domain="*" to-ports="*"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*"  to-ports="*"/>
<allow-http-request-headers-from domain="*"/>
<site-control permitted-cross-domain-policies="all"/>

但是从Unity内部,如果我尝试以下代码,我会遇到问题。

private void QueryAIServer()
{
    string url = "http://192.168.1.116/locJSON.txt";
    WWW AIServer = new WWW(url);

    while(!AIServer.isDone) { };

    Debug.Log("Connected to AI Server!");
}

当我越过while行时,如果我在调试器中检查AIServer变量,我可以看到消息&#34; System.Security.SecurityException:没有可用的有效跨域策略允许访问&#34;用红色绘制的AIServer.bytes,AIServer.data和AIServer.text

另外,我确实在控制台中输出了以下消息。任何见解都将不胜感激。

  

UriFormatException:无效的URI:无法确定URI的格式。

     

MonoForks.System.Uri..ctor(System.String uriString,Boolean dontEscape)MonoForks.System.Uri..ctor(System.String uriString)(wrapper remoting-invoke-with-check)MonoForks.System.Uri: .ctor(string)MonoForks.System.Windows.Interop.PluginHost.get_SourceUri()MonoForks.System.Windows.Browser.Net.CrossDomainPolicyManager.GetCachedWebPolicy(MonoForks.System.Uri uri)UnityEngine.UnityCrossDomainHelper.GetSecurityPolicy(System.String requesturi_string, IPolicyProvider policyProvider)UnityEngine.UnityCrossDomainHelper.GetSecurityPolicy(System.String requesturi_string)UnityEngine.WWW:get_isDone()PlayEditorMain:QuerryAIServer()(在Assets / Scripts / Play Editor Scripts / Menu Scripts / PlayEditorMain.cs:556)PlayEditorMain:ButtonPressed(GameObject )(在Assets / Scripts / Play Editor脚本/菜单脚本/ PlayEditorMain.cs:262)MainMenuButton:OnClick()(在Assets / Scripts / Play Editor脚本/菜单按钮/ MainMenuButton.cs:23)UnityEngine.GameObject:SendMessage( String,Object,SendMessageOptions)U ICamera:Notify(GameObject,String,Object)(在Assets / 3rd Party / NGUI / Scripts / UI / UICamera.cs:765)UICamera:ProcessTouch(布尔值,布尔值)(在Assets / 3rd Party / NGUI / Scripts / UI / UICamera.cs:1435)UICamera:ProcessMouse()(在Assets / 3rd Party / NGUI / Scripts / UI / UICamera.cs:1063)UICamera:Update()(在Assets / 3rd Party / NGUI / Scripts / UI / UICamera。 CS:909)

You are trying to load data from a www stream which had the following error when downloading. Rejected because no crossdomain.xml policy file was found UnityEngine.WWW:get_assetBundle() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

Unable to determine the audio type from the URL (http://192.168.1.116/locJSON.txt) . Please specify the type. UnityEngine.WWW:get_audioClip() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

Streaming of 'ogg' on this platform is not supported UnityEngine.WWW:get_oggVorbis() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

You are trying to load data from a www stream which had the following error when downloading. Rejected because no crossdomain.xml policy file was found UnityEngine.WWW:get_size() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

You are trying to load data from a www stream which had the following error when downloading. Rejected because no crossdomain.xml policy file was found UnityEngine.WWW:get_texture() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

You are trying to load data from a www stream which had the following error when downloading. Rejected because no crossdomain.xml policy file was found UnityEngine.WWW:get_textureNonReadable() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

Unable to determine the audio type from the URL (http://192.168.1.116/locJSON.txt) . Please specify the type. UnityEngine.WWW:get_audioClip() PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:559) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

Connected to AI Server! UnityEngine.Debug:Log(Object) PlayEditorMain:QuerryAIServer() (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:558) PlayEditorMain:ButtonPressed(GameObject) (at Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262) MainMenuButton:OnClick() (at Assets/Scripts/Play Editor Scripts/Menu Buttons/MainMenuButton.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) UICamera:Notify(GameObject, String, Object) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:765) UICamera:ProcessTouch(Boolean, Boolean) (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1435) UICamera:ProcessMouse() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:1063) UICamera:Update() (at Assets/3rd Party/NGUI/Scripts/UI/UICamera.cs:909)

2 个答案:

答案 0 :(得分:1)

有一件事让我多次这样做并没有将它保存为UTF-8编码。如果您在记事本中打开它并在进行更改后重新保存,则有些编辑会执行此操作。记事本(至少是Windows 8.1中的版本)有一个选择框,用于检查保存时要使用的编码类型,默认为ANSI。

编辑: 我想确定一件事 - 我确定你只是省略了它,但为了清楚起见,交叉域中的标签需要被<cross-domain-policy></cross-domain-policy>包围,而第一个元素就像所有XML一样文件总共需要<?xml version="1.0" ?> ..

<?xml version="1.0" ?>
<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*" to-ports="*" secure="false"/>
    <allow-access-from domain="*" to-ports="*"/>
    <allow-access-from domain="*"/>
    <allow-http-request-headers-from domain="*"  to-ports="*"/>
    <allow-http-request-headers-from domain="*"/>
    <site-control permitted-cross-domain-policies="all"/>
</cross-domain-policy>

答案 1 :(得分:0)

尝试此标准允许所有crossdomain.xml:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>

   <allow-access-from domain="*" secure="false" />
</cross-domain-policy>