1 Reply Latest reply on Aug 24, 2010 10:46 AM by Aaronius9er9er

    HTTP Status Code from NetConnection

    Aaronius9er9er

      Hey flexers,

       

      I have a flex app that requires a user to be logged in to make service calls.  If the user isn't logged in or the session times out and the app makes a call to a backend service via AMF, the server responds with an HTTP status code 401, as expected.  The response header looks like this:

       

       

      HTTP/1.1 401 Authorization Required

      Date: Wed, 18 Aug 2010 16:49:01 GMT

      Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g

      X-Powered-By: PHP/5.2.4-2ubuntu5.6

      x-ec2-instance-id: i-e52e8b8f

      Cache-Control: no-store, no-cache, must-revalidate

      Pragma: no-cache

      P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

      Cache-Control: post-check=0, pre-check=0

      Content-Length: 185

      Content-Type: application/x-amf

      Expires: 0

       

      The response content is AMF so it's binary but here's the hex as reported by the Charles Web Debugging Proxy:
      00000000  00 00 00 00 00 01 00 0b 2f 31 2f 6f 6e 53 74 61           /1/onSta
      00000010  74 75 73 00 00 ff ff ff ff 10 00 1b 66 6c 61 73   tus         flas
      00000020  68 2e 65 76 65 6e 74 73 2e 4e 65 74 53 74 61 74   h.events.NetStat
      00000030  75 73 45 76 65 6e 74 00 04 69 6e 66 6f 10 00 06   usEvent  info 
      00000040  4f 62 6a 65 63 74 00 07 6d 65 73 73 61 67 65 02   Object  message
      00000050  00 61 59 6f 75 72 20 73 65 73 73 69 6f 6e 20 69    aYour session i
      00000060  73 20 6e 6f 20 6c 6f 6e 67 65 72 20 61 63 74 69   s no longer acti
      00000070  76 65 2e 20 20 54 68 69 73 20 69 73 20 6c 69 6b   ve.  This is lik
      00000080  65 6c 79 20 64 75 65 20 74 6f 20 69 6e 61 63 74   ely due to inact
      00000090  69 76 69 74 79 2e 20 50 6c 65 61 73 65 20 72 65   ivity. Please re
      000000a0  2d 6c 6f 67 69 6e 20 74 6f 20 63 6f 6e 74 69 6e   -login to contin
      000000b0  75 65 2e 00 00 09 00 00 09                        ue.     
      I'm looking for the proper way, in the Flex app, to figure out it's a 401 status code.  Previously, we were watching for the NetStatusEvent coming from NetConnection. If there was a info.errorCode property, we'd use that as the status code.  Otherwise, if there was an info.description property, it would normally look like "HTTP: Status 401" in which case we'd pull it out of the string (which makes me cringe just thinking about it).  However, at the moment the NetStatusEvent looks like this:
      error flash.events.NetStatusEvent (@6a7eee1)
      [inherited]
      info Object (@7f3ea79)
      code "NetConnection.Call.Failed"
      description "HTTP: Failed"
      level "error"
      m_info Object (@7f3ea79)
      No status code exists in the event anywhere in the event.  After all kinds of debugging, rolling back code, etc., I can't figure out why the NetStatusEvent now has description "HTTP: Failed" instead of description "HTTP: Status 401".
      Can anyone clarify what's going on?  Thanks.
        • 1. Re: HTTP Status Code from NetConnection
          Aaronius9er9er Level 1

          After digging into it more, I've found that it's browser-specific behavior.  When simulating an HTTP status code of 401, in Chrome and IE I get a NetStatusEvent that looks like this:

           

          error flash.events.NetStatusEvent (@6c33791)

          [inherited]

          info Object (@6b14851)

          code "NetConnection.Call.Failed"

          description "HTTP: Status 401"

          details "http://aaronhardy.com/test.php"

          level "error"

          m_info Object (@6b14851)

           

          Notice the "description" has the status code.  In Firefox I get an event that looks like this:

          error flash.events.NetStatusEvent (@6c33791)

          [inherited]

          info Object (@6b14851)

          code "NetConnection.Call.Failed"

          description "HTTP: Failed"

          details "http://aaronhardy.com/test.php"

          level "error"

          m_info Object (@6b14851)

           

          Notice the status code isn't mentioned anywhere.  Is this a known issue in Firefox?  Are we really that close to being able to use real HTTP status codes yet so far away?

           

          Aaron