flash请求来源Refer测试

最近做了个小小的测试:A域有一个parent.swf,加载了B域的child.swf,B域的child.swf发出的请求,服务器收到的refer是来自A域的parent.swf ,还是来自B域的child.swf。  

测试环境:

  系统:win 8、

  Chrome 24.0.1312.57 m、 >  Flash Player 11,6,602,155

  Firefox 19.0 > Flash Player 11,6,602,155

  IE 10 > Flash Player 11,6,602,167

 

测试结果:

请求方式\浏览器 chrome firefox ie
GET father.swf father.swf son.swf
POST father.swf son.swf son.swf

parent.swf 是用 Adobe Flash Professional CS5 编辑的,代码直接写在时间轴里:

A域的 parent.swf 负责加载 B域的 child.swf 并显示在舞台上

package 
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.net.URLRequest;
    
    /**
     * 主flash
     * @author @ASV5 - http://weibo.com/rich
     */
    public class Main extends Sprite 
    {
        
        public function Main():void 
        {
            addEventListener(Event.ENTER_FRAME, checkStage);
        }
        
        private function checkStage(e:Event):void 
        {
            if (stage.stageWidth > 0 && stage.stageHeight > 0)
            {
                removeEventListener(Event.ENTER_FRAME, checkStage);
                init();
                loadSWF("http://www.B.com/FatherSonRequest/son.swf");
            }
        }
        
        private function init():void 
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            graphics.beginFill(0x9BA224);
            graphics.lineStyle(2,0x333333);
            graphics.drawRect(1, 1, stage.stageWidth - 2, stage.stageHeight - 2);
            graphics.endFill();
        }
        
        private function loadSWF(swfURL:String):void
        {
            if (swfURL == null || swfURL == "") return;
            var rs:URLRequest = new URLRequest(swfURL);
            var ld:Loader = new Loader();
            ld.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoaded);
            ld.load(rs);
        }
        
        private function onDataLoaded(e:Event):void 
        {
            var tgt:Loader = e.target.loader as Loader;
            addChild(tgt);
        }
        
        
    }
    
}

 

 

现在是child.swf 的源码,用Flash Develop 编译的

package  
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.external.ExternalInterface;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    import flash.system.Security;
    
    /**
     * ...
     * @author @ASV5 - http://weibo.com/rich
     */
    public class Son extends Sprite 
    {
        private var url:String = "http://www.mysite.com/request.php";
        public function Son() 
        {
            Security.allowDomain("*");
            init();
            //getRS();
            postRS();
        }
        
        private function init():void 
        {
            graphics.beginFill(0xCACACA);
            graphics.lineStyle(1, 0xB3B3B3);
            graphics.drawRect(0, 0, 300, 300);
            graphics.endFill();
        }
        
        private function postRS():void
        {
            var rs:URLRequest = new URLRequest(url);
            rs.method = URLRequestMethod.POST;
            var ld:URLLoader = new URLLoader();
            var d:URLVariables = new URLVariables();
            d.name = "ASV5";
            rs.data = d;
            ld.addEventListener(Event.COMPLETE, onDataLoaded);
            ld.load(rs);
        }
        
        private function getRS():void
        {
            var rs:URLRequest = new URLRequest(url);
            var ld:URLLoader = new URLLoader();
            ld.addEventListener(Event.COMPLETE, onDataLoaded);
            ld.load(rs);
        }
        
        private function onDataLoaded(e:Event):void 
        {
            var data:String = e.target.data as String;
            console(data);
            trace(data);
        }
        
        private function console(log:String):void
        {
            if (ExternalInterface.available)
            {
                //ExternalInterface.call("console.log("+ log +")");
                ExternalInterface.call("console.log", log);

            }
        }
        
    }

}

 

posted on 2011-02-17 16:28  ASV5  阅读(728)  评论(0)    收藏  举报