2009-12-07 24 views
1

URLRequest在AS3的跨域中不起作用?URLRequest在As3的Cross域中不起作用?

<?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> 

在XML跨域:

<?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> 

我怎樣才能解決這個問題?

它可以在我上傳到我自己的主機但不在本地機器上時使用。

+0

你使用的URLRequest是什麼?一個URLRequest只是一個URL,它並沒有對自己的 – Marius 2009-12-07 01:40:02

+0

順便說一句,在http://abcomp01.thaifasthost.com/crossdomain.xml策略文件的結構不加載任何東西。 – Amarghosh 2009-12-07 04:48:41

回答

1

你在做什麼URLRequest對象?需要確定的一件事是,您嘗試連接到該服務器的服務器上存在crossdomain.xml策略文件。

+0

如果該域名沒有>所以我不能用來翻錄網站? – 2009-12-07 01:49:11

+0

是。這是保護您嘗試連接的域的安全措施。 – 2009-12-07 12:55:28