Using crossdomain.xml (Error #2048 Error #2170…) 使用crossdomain控制跨域访问

当试图与某站外URL的进行数据交互时 (如通过URLLoader), 如果目标站点无crossdomain.xml或该文件未允许当前站点的访问, 则会出现#2048, #2170等错误.

image
Cross-domain policy file specification (PDF, 129 KB)

关于crossdomain.xml: http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html

具体的错误信息:
Error #2048: Security sandbox violation: http://liguoliang.com/NetworkSpeedTest.swf cannot load data from…. , Or:
Error #2170 : Security sandbox violation: http://liguoliang.com/NetworkSpeedTest.swf cannot send HTTP headers to http://api.myspace.com/v1/users/**/mood.xml

解决方法: 在目标站点根目录下放置crossdomain.xml 跨域访问文件. 最简单的一个, 允许所有:

<?xml version="1.0"?>


  
  
  

 

如: MySpace的API的crossdomain.xml 

另: crossdomain.xml不必一定置于根目录下,参见: Security.loadPolicyFile.

This entry was posted in ActionScript, Flex and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>