0 Replies Latest reply on Nov 25, 2010 9:59 AM by yaguilar20

    Problem when using HTTPService method post to consume rest services with flex4




      I have a problem when trying to call a rest service using httpservice with the method post. When I do this I get the next error:


        body = ""
        clientId = "DirectHTTPChannel0"
        correlationId = "CA6375C6-095B-5BD2-961A-840DBF1B1913"
        destination = ""
        extendedData = (null)
        faultCode = "Server.Error.Request"
        faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Error de secuencia. URL: http://localhost:8084/sitifac-services/resources/receptor/alta/"]. URL: http://localhost:8084/sitifac-services/resources/receptor/alta/"
        faultString = "HTTP request error"
        headers = (Object)#1
          DSStatusCode = 0


      And I don't know hot to resolve it, I have been searching in google but I can't find a lot of information about the solution. I've tried with a simple component httpservice, and with an URLRequest too, and now creating an object of the httpservice component, but it doesn't work.

      Besides I've tried adding the -use-network= true or -user-network=false in the flex project's compiler properties, I added a crossdomain.xml too but doesn't work.


      I'll really apreciate if anyone could help me to resolve it. Thanks in advance.


      This is my code:


      These are the imports I use:

      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.http.HTTPService;
      import json.JParser;


      Then I create a httpservice object:

      private var uriBase: String = "http://localhost:8084/sitifac-services/resources/receptor/alta/";


      private function saveUser() : void {       
                    var service: HTTPService = new HTTPService();       
                    service.contentType = "application/json";       
                    service.method = "POST";       
                    service.resultFormat = "text";       
                    service.url = uriBase;       
                    service.useProxy = false;       
                    service.addEventListener( FaultEvent.FAULT , function(event:FaultEvent):void {               
                        Alert.show( event.message.toString() );           
                    } )             
                    service.addEventListener( ResultEvent.RESULT , function(event:ResultEvent):void {             
                        var response: Object = JParser.decode( event.message.body.toString() );             
                    } )


                   // Here I create my object and then enconding it to json
                    var objetoReceptorTmp:Object = new Object;
                    objetoReceptorTmp.receptorPK = objetoReceptorPk;
                    objetoReceptorTmp.emisor = objetoEmisorTmp;
                    objetoReceptorTmp.entidad = objetoEntidad;
                    var json:String = JParser.encode( objetoReceptorTmp );       
                    var jsonData:ByteArray = new ByteArray();       
                    jsonData.position = 0;       
                    var contentType:String = "application/x-www-form-urlencoded";       
                    var receptor:String = "receptor="+jsonData;
                    service.send( receptor);    



      And the button that call this function is:

      <mx:Button label="Save" width="96" click="saveUser()"/>