解决flex跨域访问

Flex 跨域访问解决方案

想让swf 文件在一台服务器上运行并且能够访问另一台服务器上的资源,这时就会遇到跨域问题,请看下面的解决方案。

写一个名字为 crossdomain.xml 的XML文件,这个方法是允许任何Flash都可以调用,放到被调用文件的网站根目录下:
view plaincopy to clipboardprint?
<?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="*" /> 
</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="*" />
</cross-domain-policy>


只让你允许的网站来调用你的数据.
view plaincopy to clipboardprint?
<?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="www.yoursite.com " /> 
<allow-access-from domain="yoursite.com" /> 
<allow-access-from domain="*.k-zone.cn" /> 
</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="www.yoursite.com " />
<allow-access-from domain="yoursite.com" />
<allow-access-from domain="*.k-zone.cn" />
</cross-domain-policy>

如果使用XMLSocket要把端口号加上
view plaincopy to clipboardprint?
<cross-domain-policy> 
<allow-access-from domain="*.foo.com" to-ports="507,516" /> 
<allow-access-from domain="*.bar.com" to-ports="516-523" /> 
<allow-access-from domain="www.foo.com " to-ports="507,516-523" /> 
<allow-access-from domain="202.117.80.202" to-ports="*" /> 
</cross-domain-policy> 
<cross-domain-policy>
<allow-access-from domain="*.foo.com" to-ports="507,516" />
<allow-access-from domain="*.bar.com" to-ports="516-523" />
<allow-access-from domain="www.foo.com " to-ports="507,516-523" />
<allow-access-from domain="202.117.80.202" to-ports="*" />
</cross-domain-policy>


如果安全策略文件放在根目录,文件名字必须为crossdomain.xml,如果不放在根目录,
要用flash.system.security.loadPolicyFile("http://xcopy.net.cn/crossdomain.xml ")
这样的方法加载安全策略文件。

http://localhost:8080/crossdomain.xml

如果以上还不能成功访问,请再住下看:
请注意代码中的:<param name="allowScriptAccess" value="always"/>
view plaincopy to clipboardprint?
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width=512px height=384px 
      codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab "> 
      <param name="movie" value="http://www.xcopy.net.cn/test.swf " /> 
      <param name="quality" value="high" /> 
      <param name="allowScriptAccess" value="always"/>      
      <embed src="http://www.xcopy.net.cn/test.swf " quality="high" bgcolor="#869ca7" 
        width=512px height=384px name="/test" align="middle" 
        type="application/x-shockwave-flash" 
        allowScriptAccess="always" 
        pluginspage="http://www.adobe.com/go/getflashplayer "> 
      </embed> 
</object> 


注意:crossdomain.xml的存放位置,视你的应用服务器类型

1、tomcat:  server根目录/webapps/root.war/crossdomain.xml(测试通过)

2、spring dm server 或者 eclipse virgo web server:   server根目录/pickup/splash.war/crossdomain.xml(测试通过)

其他应用服务器也是放在该服务的管理应用根目录下

你可能感兴趣的:(xml,应用服务器,Flex,Flash,Access)