1 Reply Latest reply on Apr 2, 2014 11:16 AM by sdwareham

    Calling a service and passing paramerters with URLLoader

    sdwareham

      I'm trying to connect my mobile flex project to web service. The service returns JSON. I'm not too familiar with this, and and tried to put something together from a few online samples. Can anyone see if I am missing something, or have something wrong. I can't get this to work yet, I'm just getting the error "Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: ..."

       

      I'm trying to pass two paramters to the service (username/password) and send it using POST. Any suggestions would be really appreciated!

       

      //========================================================\\

       

      var loader:URLLoader = new URLLoader();

      var request:URLRequest = new URLRequest("https://myurl");

       

      var variables:URLVariables = new URLVariables();

             variables.username = "name";

             variables.password = "password";

             request.data = variables;

       

             request.method = URLRequestMethod.POST;

       

      var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");

            request.requestHeaders.push(header);

       

      loader.addEventListener(Event.COMPLETE, handleComplete);

       

                                              try {

                                                        aloader.load(request);

                                                   }

                          catch (error:Error)

                              {

                                                        trace(error);

                                                   }

       

                                              function handleComplete(e:Event):void

                                              {

                                                        trace("It worked.");

                                              }