2016-06-13 69 views
-5

我試圖使用URLLoader對象從我的Web服務器加載遠程內容。爲此,我使用了Adobe幫助中的example代碼。加載遠程內容時出現「錯誤#2032:流錯誤」

這裏是我的嘗試:

var loader:URLLoader; 

loader = new URLLoader(); 
configureListeners(loader); 

var request:URLRequest = new URLRequest("http://www.fashionboxpk.com/Test2.php"); 
try 
{ 
    loader.load(request); 
} 
catch (error:Error) 
{ 
    trace("Unable to load requested document."); 
} 

function configureListeners(dispatcher:IEventDispatcher):void 
{ 
    dispatcher.addEventListener(Event.COMPLETE, completeHandler); 
    dispatcher.addEventListener(Event.OPEN, openHandler); 
    dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler); 
    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
    dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); 
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 
} 
function completeHandler(event:Event):void 
{ 
    var loader:URLLoader = URLLoader(event.target); 
    trace("completeHandler: " + loader.data); 
} 
function openHandler(event:Event):void 
{ 
    trace("openHandler: " + event); 
} 
function progressHandler(event:ProgressEvent):void 
{ 
    trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal); 
} 
function securityErrorHandler(event:SecurityErrorEvent):void 
{ 
    trace("securityErrorHandler: " + event); 
} 
function httpStatusHandler(event:HTTPStatusEvent):void 
{ 
    trace("httpStatusHandler: " + event); 
} 
function ioErrorHandler(event:IOErrorEvent):void 
{ 
    trace("ioErrorHandler: " + event); 
} 

但是編譯時,我得到這樣的輸出:

openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2] 
progressHandler loaded:384 total: 384 
Error opening URL 'http://www.fashionboxpk.com/Test2.php' 
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=406 responseURL=null] 
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.fashionboxpk.com/Test2.php"] 

那麼,怎樣才能避免我這些錯誤,並正確加載的內容?

+0

看起來在[http://www.fashionboxpk.com/crossdomain.xml](http:/)上不存在crossdomain.xml /www.fashionboxpk.com/crossdomain.xml) –

+0

歡迎來到堆棧溢出。請閱讀[this](http://stackoverflow.com/questions/ask/advice)瞭解誰提出了很好的問題。好的問題在SO上得到了很好的答案。不好的問題往往會被忽略。 –

+0

這是一個問題嗎?解釋你真的**在這裏嘗試實現...使用AS3打開瀏覽器選項卡中的PHP頁面?或者將php頁面內容讀入AS3? –

回答

0

您的crossdomain.xml聲明只允許來自您自己的域的請求(並且您不需要從您自己的域中讀取crossdomain.xml)。

因此,如果您嘗試通過從服務器加載內容來在本地進行測試,它將無法工作。雖然我相信在這種情況下你應該得到安全沙箱違例錯誤。

你正在收到的HTTP狀態說406(「不可接受」)。所以你可能會改變你的跨域,所以它允許來自其他域的請求,或者檢查你的服務器設置,如果有什麼特別的PHP文件。

對於開始,測試這個作爲你的crossdomain.xml:

<?xml version="1.0" ?> 
<cross-domain-policy> 
    <allow-access-from domain="*" /> 
</cross-domain-policy> 

注意,這樣使得任何域發送請求到服務器,這是一個嚴重的安全隱患。這對於測試是很好的,但是您應該在此處爲生產系統指定顯式域名

相關問題