HttpService错误#2096

时间:2013-02-04 13:50:04

标签: actionscript-3 flex http-headers httpservice

我已经编写了一个Httpservice来从服务器获取数据,但是当我尝试运行该服务时,我得到了错误(#2096)。以下是我的代码:

package

{

import flash.net.URLRequestHeader;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.messaging.AbstractConsumer;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

public class JSONDataLoader
{

    private var httpService:HTTPService;

    private var errVO:ErrVO;
    [Bindable]
    public var errAC:ArrayCollection = new ArrayCollection();

    [Bindable]
    public var errStr:String;

    public function JSONDataLoader(url:String)
    {
        httpService = new HTTPService();
        httpService.url = url;
        httpService.method = "POST";
        httpService.contentType = "application/json";

        var headerParams:Object = new Object();

        headerParams["Host"] = "192.168.11.59:3333";
        headerParams["Content-Length"] = 347;

        httpService.headers = headerParams;

        var parameters:Object = new Object();
        parameters["FromDate"] = "01-01-2013 18:30";
        parameters["Location"] = "String content";
        parameters["LocationId"] = 2147483647;
        parameters["ReportId"] = 9223372036854775807;
        parameters["ReportName"] = "String content";
        parameters["Team"] = "17,22,30,1,40,53,55,69,70,73,77";
        parameters["TeamId"] = 2147483647;
        parameters["ToDate"] = "01-01-2013 18:30";

        httpService.send(parameters);
        httpService.addEventListener(ResultEvent.RESULT, resultHandler);
        httpService.addEventListener(FaultEvent.FAULT, faultHandler);
    }

    private function resultHandler(event:ResultEvent):void
    {
        var rawData:String = String(event.result);
        var obj:Object = JSON.parse(rawData);

        Alert.show("Data: " + rawData);
    }

    private function faultHandler(event:FaultEvent):void 
    {
        errStr = event.fault.faultString+" "+event.message;
        Alert.show("Error!!!" + errStr);

    }
}

}

我在这做什么。我的标题或请求正文有问题。

请帮助我,因为我从过去2天开始坚持这一点。

以下是完整的错误消息...

错误!!!错误#2096(mx.messaging.messages :: HTTPRequestMessage)#0   body =(对象)#1     FromDate =“01-01-2013 18:30”     Location =“字符串内容”     LocationId = 2147483647     ReportId = 9223372036854776000     ReportName =“字符串内容”     球队=“17,22,30,1,40,53,55,69,70,73,77”     TeamId = 2147483647     ToDate =“01-01-2013 18:30”   clientId =(null)   contentType =“application / json”   destination =“DefaultHTTP”   headers =(Object)#2     DSEndpoint =“direct_http_channel”   httpHeaders =(对象)#3     内容长度= 347     主持人=“192.168.11.59:3333”   messageId =“C130487E-0EBA-375E-E71D-A580EFE175EE”   method =“POST”   recordHeaders = false   timestamp = 0   timeToLive = 0   url =“我的网址”

1 个答案:

答案 0 :(得分:0)

您可能需要检查参数的内容是否包含非法字符,例如'<'或者'>'。用'&替换它们l t;'或者'& g t;' (没有空格)可以解决问题。

当HttpService发送或接收包含这两个标记的字符串时,可能会发生错误。

使用URLRequest是一个更好的选择,因为它可以摆脱这个问题。