Unity crossdomain.xml

本文关键字:xml crossdomain Unity | 更新日期: 2023-09-27 18:19:28

我收到了关于crossdomain.xml文件的错误消息,我不知道如何解决它。我从web浏览器访问URL没有问题。

从web浏览器

http://192.168.1.116:80/locJSON.txt

很好地给了我一个JSON的大片段

从web浏览器

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变量内部,我可以看到AIServer.bytes、AIServer.data和AIServer.text 的红色消息"System.Security.SecurityException:No valid cross-domain policy available to allow access"

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

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

MonoForks.System.Uri..ctor(System.String uriString,布尔dontEscape)MonoForks.System.Uri..ctorUnityEngine.UnityCrossDomainHelper.GetSecurityPolicy(System.String requesturi_String,IPolicyProviderpolicyProvider)UnityEngine.UnityCrossDomainHelper.GetSecurity Policy(System.String requesturi_String)UnityEngine WWW:get_isDone()PlayEditorMain:QueryAIServer()(位于Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain。cs:556)PlayEditor Main:ButtonPressed(游戏对象)(位于Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs:262)主菜单按钮:点击()(在Assets/3rd Party/NGUI/Scripts/UI/UiCamer.cs:1435)UICamera:ProcessMouse()

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)

Unity crossdomain.xml

让我多次关注的一件事是,没有将其保存为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>

尝试这个标准允许所有跨域.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>