AIR多个HTTPService调用Mac OSX

时间:2011-09-27 17:37:01

标签: macos air httpservice

我正在实例化并发送多个HTTPService实例 但是,在Mac上,许多调用因2032错误而失败。

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       click="windowedapplication1_clickHandler(event)"
                       creationComplete="windowedapplication1_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;

            [Bindable]
            private var r:int=0;
            [Bindable]
            private var f:int=0;

            private var a:Array= ['url1', 'url2', 'url3', 'url4', 'url5'];

            private var sa:Array=[];
            protected function windowedapplication1_clickHandler(event:MouseEvent):void
            {
                for(var i:int=0; i<sa.length; i++) {
                    sa[i].send();
                }

            }

            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                for(var i:int=0; i<100; i++) {
                    var random:int=Math.floor(Math.random() * a.length);
                    var s:HTTPService=new HTTPService();
                    s.addEventListener(ResultEvent.RESULT, sr);
                    s.addEventListener(FaultEvent.FAULT, sf);
                    s.resultFormat="text";
                    s.url=a[random];
                    sa.push(s);
                }
                //s.useProxy=true;
            }

            private function sf(e:FaultEvent):void {
                f++;
                t.text="MESSAGE: " + e.message + "HEADERS:" + e.headers + "FAULTCONTENT: " + e.fault.content 
                    + "ERROR: " + e.fault.errorID + "|" + e.fault.faultCode + "|" + e.fault.faultDetail + "|" + e.fault.faultString
                    + "FAULTMESSAGE:" + e.fault.message + "FAULRNAME:" + e.fault.name + "ROOTCAUSE:" + e.fault.rootCause
                    + "AT " + e.fault.getStackTrace();
            }

            private function sr(e:ResultEvent):void {
                r++;
            }

        ]]>
    </fx:Script>

    <fx:Declarations>

    </fx:Declarations>
    <s:Label x="10" y="19" text="Result {r}"/>
    <s:Label x="10" y="120" text="Fault {f}"/>
    <s:TextArea x="10" y="198" width="610" height="294" id="t"/>
</s:WindowedApplication>

它在PC上按预期工作(我得到了所有100个成功的结果),但在Mac上,我得到了一些失败的wuite。 为什么会发生这种情况?如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

似乎Win7和Mac OS X阻止了对不同地址的非常快速的请求。 添加1秒超时工作正常