2

I'm sending POST request using URLLoader and URLRequest with XML data. Then API sends response with redirect page(Location header) and i want to get this URL. How do I catch this response?

UPD:

Event.COMPLETE in debugger:

event = flash.events.Event (@6e1edf9) 
 bubbles = false 
 cancelable = false 
 currentTarget = flash.net.URLLoader (@418e241) 
  [inherited] =  
  bytesLoaded = 1 
  bytesTotal = 0 
  data = " " 
  dataFormat = "text" 
  stream = flash.net.URLStream (@77c5fb9) 
   [inherited] =  
   bytesAvailable = 0 
   connected = true 
   endian = "bigEndian" 
   objectEncoding = 3 
 eventPhase = 2 
 target = flash.net.URLLoader (@418e241) 
  [inherited] =  
  bytesLoaded = 1 
  bytesTotal = 0 
  data = " " 
  dataFormat = "text" 
  stream = flash.net.URLStream (@77c5fb9) 
 type = "complete"
2xMax
  • 1,639
  • 6
  • 21
  • 41
  • My guess is that Flex handles the redirectionn automatically, and that you need not (and cannot) read the headers - but I could be wrong. – Amarghosh Oct 06 '10 at 09:53
  • i tried to add an Event.Complete handler. but event doesn't contain this url. See UPD-view of event in debugger – 2xMax Oct 06 '10 at 10:07
  • If this is a server side redirect; how would the client (Flash Player) even know a redirect was taking place? – JeffryHouser Oct 06 '10 at 13:30
  • 2www.Flextras.com: via response in header that named as "Location". see example with custom library(it isn't work with my service that uses ssl) http://stackoverflow.com/questions/2561445/handling-redirected-url-within-flex-app – 2xMax Oct 06 '10 at 13:48
  • 2
    You can not get `Location` header while using `URLLoader` or `Loader`. Using custom HTTP clients like one you wrote may be painful so be careful. More than than they will not connect to any server - they need socket policy file to be passed first. – Maxim Kachurovskiy Oct 06 '10 at 14:15
  • 1
    If you're using AIR, you can use the `httpResponseStatus` event to get this. Apparently, if you're not using AIR, the values are set to null. http://stackoverflow.com/questions/185761/access-http-response-headers-in-for-flash-net-urlloader-object – Mims H. Wright Apr 06 '11 at 20:43

1 Answers1

1

Listen on the httpResponseStatus event of the URLLoader. The event details contains a property called responseHeaders that can provide you with location header. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#event:httpResponseStatus for details.

Also, to prevent redirect you can set followRedirects on URLRequest to false. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#followRedirects for details.

sangupta
  • 2,396
  • 3
  • 23
  • 37