0
votes

I've written a Httpservice to get data from server but when I tried to run the service it got me the error (#2096). Below is my code:

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);

    }
}

}

What i am doing worng here. Is there problem with my headers or request body.

Please help me, as i am stuck with this from past 2 days.

Here is the full error message...

Error!!!Error #2096 (mx.messaging.messages::HTTPRequestMessage)#0 body = (Object)#1 FromDate = "01-01-2013 18:30" Location = "String content" LocationId = 2147483647 ReportId = 9223372036854776000 ReportName = "String content" Team = "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 = (Object)#3 Content-Length = 347 Host = "192.168.11.59:3333" messageId = "C130487E-0EBA-375E-E71D-A580EFE175EE" method = "POST" recordHeaders = false timestamp = 0 timeToLive = 0 url = "my url"

1
Does the service require any authentication that you need to pass through the header? If not, I would suggest you create an html page with the input text field's names and values matched what you describe, then post to the service you write and see if it indeed returns the desire JSON string.Tianzhen Lin
Also, try using something like Charles Proxy to inspect the traffic going back & forth.Amy Blankenship
Hello Tianzhen and Amy thanks for looking into this. Authentication password are not reqyuired in this service. Please can you tell what is the problem or where I am going wrong.Rocker
Hey guys, I've achieved the same through a different way. I dropped the idea of using HTTP Service and used URL Request and it worked for me. Anyways thanks for all your help. Happy coding... :-)Rocker

1 Answers

0
votes

You may need to check if the content of the parameters contains illegal characters like '<' or '>'. Replacing them with '& l t ;' or '& g t ;' (without spaces) may solve the problem.

Errors may occur when HttpService sends or receives strings including these two marks.

Using URLRequest would be a better choice since it would be free from this problem.