Flex解决跨域问题的策略文件的写法
发布时间:2020-12-15 04:17:22 所属栏目:百科 来源:网络整理
导读:/***************************策略文件 crossdomain.xml***************************/? 一、基础解说? 用Flash文档访问另一个域中的数据。Flash Player会自动试图从该域加载策略文件。? 如果试图访问数据的Flash文档所在的域包括在该策略文件中,则数据将自
/***************************策略文件 crossdomain.xml***************************/?
一、基础解说? 用Flash文档访问另一个域中的数据。Flash Player会自动试图从该域加载策略文件。? 如果试图访问数据的Flash文档所在的域包括在该策略文件中,则数据将自动成为可访问数据。? 策略文件必须命名为 crossdomain.xml,并且可以驻留在服务器的根目录和其它目录之中,这个服务器提供要被访问的ActionScript数据。? 每个策略文件对于它所驻留的服务器的端口和协议是特定的,只有在通过HTTP、HTTPS或FTP进行通信的服务器上,策略文件才起作用。? flashplayer升级到9.124之后,加强了安全性,之前的crossdomain.xml的写法发生了变化,以下就是该文件的完整写法:?
表示该服务允许任何外域来访问。? 关于crossdomain.xml的放置目录问题,有如下解决方案,可放置在:? 1/ 如果这个目录是容器的根目录,可以通过以下的url访问crossdomain.xml:? ??? http://localhost:8080/crossdomain.xml 。? 2/ 如果crossdomain.xml不是放在根目录下,而是在某个webapp下面,在flex中就需要在初始化的时候应用? ??? Security.loadPolicyFile("http:// localhost:8080/direc/crossdomain.xml");? ??? 其中direc是webapp的名称。? ??? 这样,外部Flex访问该服务发布的WebService时,flashplayer首先找的就是crossdomain.xml文件,若安全机制设置为允许访问,则访问成功。? 二、详细讲解:? ??? crossdomain.xml的根节点必须是cross-domain-policy:? ??? * 它包含三个子节点:site-control,allow-access-from,allow-http-request-headers-from? ??? * 无属性? ??? ??? 节点介绍:? ??? * site-control? ??? * 这个节点定义当前域的meta-policy? ??? * meta- policy决定这个域中除了master policy file以外哪些策略文件可以被client接受? ??? * 如果这个策略文件并不是 master policy file,site-control这个节点就会被忽略。? ??? * 如果你用ActionScript指定使用某个非master policy file的策略文件,你必须先检查master policy file的这个子节点以确认你指定的那个policy file是被授权的。? ??? * site-control的属性permitted-cross-domian-policies有5个选项:? ????? none--任何policy file都不被允许,包括master policy file。? ????? master-only不用解释了。? ????? by-content-type--当HTTP头的Content-Type值为text/x- cross-domain-policy才被允许。? ????? by-ftp-filename--只有以文件名结尾的URL才被允许。? ????? all--不用介绍。? ????? 默认值是master-only,除了socket policy file,它的默认值是all。? ??? * allow-access-from? ??? * allow-http-request-headers-from? ===============================================? 总:? 1、 策略文件写法:? <!--?http://www.aeroflash.org/crossdomain.xml?-->??? <!DOCTYPE?cross-domain-policy?SYSTEM?"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">?? site-control?permitted-cross-domain-policies="all"allow-access-from?domain="*"?secure="false"allow-http-request-headers-from?domain="*"?headers="*"?secure="false">?? From http://flex2.group.iteye.com/group/blog/762692? http://hi.baidu.com/wurongle_1987/blog/item/9130228adf9909739e2fb4ea.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |