4 Replies Latest reply on Nov 20, 2009 1:19 AM by paul.williams

    How to trigger FaultEvent in HTTPService

    2009 Matt Level 1

      I'm using HTTPService to make a php call and the returnFormat=text. When the call went through correctly, the result string will be returned and

      ResultEvent will be triggered and the resultHandler will be called. When there is an error on the php server, "failed" will be returned. But the FaultEvent

      will not be triggered and the "failed" string is handled as a normal return. What text message should I use in order to trigger FaultEvent?

       

      Here is the code I use to set up HTTPService:

       

      httpService = new HTTPService();
      httpService.url="http://www.xyz.com/php/test.php";
      httpService.useProxy=false;
      httpService.method="POST";
      httpService.resultFormat="text";
      httpService.addEventListener("result", httpResult);
      httpService.addEventListener("fault", httpFault);

       

       

      private function httpResult(event:ResultEvent):void {
                 // var result:Object = event.result;
                  var tmp:String=event.result.toString();
                  Alert.show(tmp);

      }

       

      private function httpFault(event:FaultEvent):void {
                  var faultString:String = event.fault.faultString;
                  Alert.show(faultString);
      }

        • 1. Re: How to trigger FaultEvent in HTTPService
          hieusua

          The FaultEvent is generated when the httpService call failed. In your case, there is no FaultEvent be dispatched because your call succeeded.

          Instead, you can trigger the "failed" string inside your httpResult

           

          private function httpResult(event:ResultEvent):void {
                     // var result:Object = event.result;
                      var tmp:String=event.result.toString();
                      if ( tmp == "failed" ) {

                              failHandler();

                      }

          }

           

          private function failHandler():void {

               // implement your code here

          }

          • 2. Re: How to trigger FaultEvent in HTTPService
            2009 Matt Level 1

            When the php server is down, the FaultEvent is triggered. I'm looking for a way that php server can trigger the FaultEvent on the client,

            even the php server is working normally.

            • 3. Re: How to trigger FaultEvent in HTTPService
              Matt Le Fevre Level 4

              2009 Matt wrote:

               

              When the php server is down, the FaultEvent is triggered. I'm looking for a way that php server can trigger the FaultEvent on the client,

              even the php server is working normally.

               

              request a HTTPService to a php file that doesn't exist

               

              or probably to a corrupted PHP file.. something like this should throw a fault i'd imagine:

               

              <?peeAY-CHpee
              
                   include 'fgdgfgdgsdfg.sdfasdf33
              
                   $bananas = file_get_contents('http://google.co.uk') * 500;
              
                   if ($bananas != 50 * Hello / Something Random)
                   {{{{{{{{{{
                        cause a fault
                        miss some
                        semicolons
                   }     
              
              //?>
              
              • 4. Re: How to trigger FaultEvent in HTTPService
                paul.williams Level 4

                The fault event of HTTPService will be triggered by an HTTP Status Code that indicates an error, such as Internal Error (500). It sounds like you are returning an OK (200) status code. More on status codes here:

                 

                http://www.w3.org/Protocols/HTTP/HTRESP.html

                1 person found this helpful