开发者

URLRequest not working in Cross domain in As3?

开发者 https://www.devze.com 2022-12-13 04:57 出处:网络
URLRequest not working in Cross domain in AS3? <?xml version=\"1.0\" encoding=\"utf-8\"?> <mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\" layout=\"absolute\" applicationComplete

URLRequest not working in Cross domain in AS3?

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
    <mx:Button x="35" y="22" label="Button" click="test()"/>
    <mx:TextArea x="35" y="65" width="365" height="254" id="aaa"/>
    <mx:Script>
        <![CDATA[

            function init():void {
      Security.allowDomain("*");  // localhost, 192.168.0.19
    Security.loadPolicyFile("http://abcomp01.thaifasthost.com/crossdomain.xml"); 
   }

            function test():void {
            var url:String = "http://bbs.pramool.com/webboard/view.php3?katoo=j530492";
            var request:URLRequest = new URLRequest(url);
            var loader : URLLoader = new URLLoader();
            request.url = url;开发者_高级运维

            request.method = URLRequestMethod.POST;
            loader.addEventListener(Event.COMPLETE, on_complete);
            loader.addEventListener(IOErrorEvent.IO_ERROR, on_error);       
            //navigateToURL(request);
                        try {
                loader.load(request);
            } 
            catch (error:Error) {
            }

            }


            function on_complete(e : Event):void{
            var loader:URLLoader = e.target as URLLoader;
            if (loader != null)
            {
                aaa.text = loader.data;
            }
        }
        function on_error(e : Event):void{
        }   
        ]]>
    </mx:Script>
</mx:Application>

In XML cross domain:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>

How can I fix this?

It works when I upload to my own hosting but not when on my local machine.


What are you doing with the URLRequest object? One thing to make sure of is that there is a crossdomain.xml policy file on the server you are trying to connect to that server.

0

精彩评论

暂无评论...
验证码 换一张
取 消