下载flexpaper源码修改后做成swf阅读器,要加入待阅读的swf文件,可以在flex里调用js的方法来获取swf文件的路径的方法,在js只专注获取路径就行,等着flex来调用:但这里会遇到一个问题那就是出现安全问题,如下的提示: Error #2044: 未处理的 onDocumentLoadedError:。 text=Error #2048: 安全沙箱冲突:http://localhost:8080/UpLoadAndDownLoad/FlexPaper.swf 不能从 http://127.0.0.1:8080/MyFileConvert/ConvertFile/application1/2.swf 加载数据。这个是由flash的跨域传输数据的安全问题所引起的,当我在tomcat的webapps/ROOT目录里加入如下文件时就可以解决这个安全问题所引去的swf的文件的不能用的问题,不过这里是将swf文件公开给所有的IP访问,所以有安全问题:
- <?xml version=”1.0″ encoding=”UTF-8″?>
- <cross-domain-policy>
- <allow-access-from domain=”*”/>
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="*"/> </cross-domain-policy>
下面转载一下关于跨域问题的内容:
http://www.xiaonei.com/crossdomain.xml
<!– http://www.xiaonei.com/ –>- <?xml version=”1.0″ encoding=”UTF-8″?>
- <cross-domain-policy>
- <allow-access-from domain=”*.xiaonei.com” />
- <allow-access-from domain=”xiaonei.com” />
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="*.xiaonei.com" /> <allow-access-from domain="xiaonei.com" /> </cross-domain-policy>
这是很标准的做法,我就让我自己的域以及我的子域来获取数据。
淘宝的:
http://www.taobao.com/crossdomain.xml
- <?xml version=”1.0″ encoding=”UTF-8″?>
- <cross-domain-policy>
- <allow-access-from domain=”*.taobao.com” />
- <allow-access-from domain=”*.taobao.net” />
- <allow-access-from domain=”*.taobaocdn.com” />
- <allow-access-from domain=”*.allyes.com” />
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="*.taobao.com" /> <allow-access-from domain="*.taobao.net" /> <allow-access-from domain="*.taobaocdn.com" /> <allow-access-from domain="*.allyes.com" /> </cross-domain-policy>
红色的一行是淘宝的CDN所在的域,所谓内容分发网络。
绿色的一行是淘宝的广告商了,http://www.allyes.com/好耶广告网络,只是不清楚是不是仍然再卖淘宝的广告?
多看几个大网站的crossdomain.xml,也可以知道可能是什么网络广告商给它们在打广告。
比如彭博:http://www.bloomberg.com/crossdomain.xml
- <?xml version=”1.0″ encoding=”UTF-8″?>
- <cross-domain-policy>
- <allow-access-from domain=”localhost” />
- <allow-access-from domain=”10.16.136.107″/>
- <allow-access-from domain=”*.bloomberg.com” />
- <allow-access-from domain=”*.pointroll.com” />
- <allow-access-from domain=”*.pointroll.net” />
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="localhost" /> <allow-access-from domain="10.16.136.107"/> <allow-access-from domain="*.bloomberg.com" /> <allow-access-from domain="*.pointroll.com" /> <allow-access-from domain="*.pointroll.net" /> </cross-domain-policy>
红色的就太不专业了,把内部IP都给暴露了。。。。。。
绿色的是彭博的广告商:PointRoll
路透的:
http://www.reuters.com/crossdomain.xml
- <?xml version=”1.0″ encoding=”UTF-8″?>
- <cross-domain-policy>
- <allow-access-from domain=”*.reuters.com” secure=”false” />
- <allow-access-from domain=”ad.doubleclick.net”
- secure=”false” />
- <allow-access-from domain=”ad.uk.doubleclick.net”
- secure=”false” />
- <allow-access-from domain=”m.2mdn.net” secure=”false” />
- <allow-access-from domain=”m2.2mdn.net” secure=”false” />
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="*.reuters.com" secure="false" /> <allow-access-from domain="ad.doubleclick.net" secure="false" /> <allow-access-from domain="ad.uk.doubleclick.net" secure="false" /> <allow-access-from domain="m.2mdn.net" secure="false" /> <allow-access-from domain="m2.2mdn.net" secure="false" /> </cross-domain-policy>
广告给了doubleclick来做(绿色)
2mdn.net看不懂是干嘛的,大概是个cdn吧。
滥情的facebook:
http://www.facebook.com/crossdomain.xml
- <?xml version=”1.0″ encoding=”UTF-8″?>
- <!DOCTYPE cross-domain-policy SYSTEM “http://www.adobe.com/xml/dtds/cross-domain-policy.dtd”>
- <cross-domain-policy>
- <site-control permitted-cross-domain-policies=”master-only” />
- <allow-access-from domain=”s-static.facebook.com” />
- <allow-access-from domain=”static.facebook.com” />
- <allow-access-from domain=”static.api.ak.facebook.com” />
- <allow-access-from domain=”*.static.ak.facebook.com” />
- <allow-access-from domain=”s-static.thefacebook.com” />
- <allow-access-from domain=”static.thefacebook.com” />
- <allow-access-from domain=”static.api.ak.thefacebook.com” />
- <allow-access-from domain=”*.static.ak.thefacebook.com” />
- <allow-access-from domain=”*.static.ak.fbcdn.com” />
- <allow-access-from domain=”external.ak.fbcdn.com” />
- <allow-access-from domain=”*.static.ak.fbcdn.net” />
- <allow-access-from domain=”external.ak.fbcdn.net” />
- <allow-access-from domain=”www.facebook.com” />
- <allow-access-from domain=”www.new.facebook.com” />
- <allow-access-from domain=”register.facebook.com” />
- <allow-access-from domain=”login.facebook.com” />
- <allow-access-from domain=”ssl.facebook.com” />
- <allow-access-from domain=”secure.facebook.com” />
- </cross-domain-policy>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="master-only" /> <allow-access-from domain="s-static.facebook.com" /> <allow-access-from domain="static.facebook.com" /> <allow-access-from domain="static.api.ak.facebook.com" /> <allow-access-from domain="*.static.ak.facebook.com" /> <allow-access-from domain="s-static.thefacebook.com" /> <allow-access-from domain="static.thefacebook.com" /> <allow-access-from domain="static.api.ak.thefacebook.com" /> <allow-access-from domain="*.static.ak.thefacebook.com" /> <allow-access-from domain="*.static.ak.fbcdn.com" /> <allow-access-from domain="external.ak.fbcdn.com" /> <allow-access-from domain="*.static.ak.fbcdn.net" /> <allow-access-from domain="external.ak.fbcdn.net" /> <allow-access-from domain="www.facebook.com" /> <allow-access-from domain="www.new.facebook.com" /> <allow-access-from domain="register.facebook.com" /> <allow-access-from domain="login.facebook.com" /> <allow-access-from domain="ssl.facebook.com" /> <allow-access-from domain="secure.facebook.com" /> </cross-domain-policy>
这么多!有子域,有CDN,有thefacebook(facebook的旧域名吧?)
还是google的专业:
- <?xml version=”1.0″?>
- <!DOCTYPE cross-domain-policy SYSTEM “http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd”>
- <cross-domain-policy>
- <site-control permitted-cross-domain-policies=”by-content-type” />
- </cross-domain-policy>
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="by-content-type" /> </cross-domain-policy>
蓝色行的意思是,要符合要求的文件你才能取,不管你是哪来的flash数据请求。符合要求的文档必须满足:Content-Type: text/x-cross-domain-policy
另:
当Flex访问WebService服务时,在本地能够正常访问,当部署到web容器中发布为web服务后,再调用WebServicIE,此时就会被拒绝访问,这就是Flex跨域访问的沙箱问题,
为了解决Flex跨域访问WebService的问题,可采用如下方案:
首先,跨域访问被拒绝是因为提供服务方没有配置安全策略文件,即crossdomain.xml,如果你不想用crossdomain.xml就要用到代理,即自己写一个后台读取webservice,然后提供给自己的flex应用,因为在flashplayer中,要跨域必须要有策略文件。考虑到 flashplayer升级到9.124之后,加强了安全性,之前的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=”*” />
- <allow-http-request-headers-from domain=”*” headers=”*” />
- </cross-domain-policy>
<?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="*" /> <allow-http-request-headers-from domain="*" headers="*" /> </cross-domain-policy>
表示该服务允许任何外域来访问。 关于crossdomain.xml的放置目录问题,有如下解决方案,可放置在: 1) 如果这个目录是容器的根目录,可以通过以下的url访问crossdomain.xml: http://localhost:8080/crossdomain.xml 。 2) 如果crossdomain.xml不是放在根目录下,而是在某个webapp下面,在flex中就需要在初始化的时候应用 Security.loadPolicyFile("http:// localhost:8080/aaa /crossdomain.xml"); 其中aaa为webapp的名称 这样,外部Flex访问该服务发布的WebService时,flashplayer首先找的就是crossdomain.xml文件,若安全机制设置为允许访问,则访问成功。
原文:http://nopainnogain.iteye.com/blog/796954
评论前必须登录!
注册