hi, guys
I'm working with a Flash based HLS player. I am unable to locate a redirect url while the request server response a 302 redirect code.
is this a bug in Flash AS3 ?
var url:String = "http://aaa.company.com/xxxx"; (response a 302 code and redirect to http://bbb.company.com/yyyy)
var req:URLRequest = new URLRequest(url);
var dispatcher:URLLoader = new URLLoader(req);
dispatcher.addEventListener(Event.COMPLETE, handlefunction);
function handlefunction(event:Event):void
{
trace(req.url);
// the console outputs "http://aaa.company.com/xxxx"
// or trace((event.currentTarget as URLRequest).url); the output is same.
// it should be "http://bbb.company.com/yyyy"
// but the event.currentTarget.data is ok.
// so how can I get the new url ?
// is this a bug in flash as3?
}
thanks.
You are tracing out the url of the request and it's still what you set it to. The request to load will not change the request.
I haven't tried doing this myself but you could try looking at the dispatches by the load function this has a responseHeaders property which might contain the redirected url?HTTPStatusEvent
I tried, it does not work.
private function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
for each(var w:URLRequestHeader in event.responseHeaders)
{
trace(w.name + ":"+w.value);
}
}
the console outputs:
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=200 responseURL=null]
I presume that it is unable to catch 302 status.
I'd not tried it myself it was just an idea, and it shouldn't matter it can catch the 302 or not on receiving the 200 status you hould still be able to see an event and therefore the response headers i was just hoping that it would contain the redirected url but here it is null.
maybe you have to set up a custom URLRequestHeader but I again I have no idea if that would work.
is there any particular reason you need to redirected url?
I tried to use Socket instead of URLRequest.
_sock = new Socket();
_sock.addEventListener(Event.CONNECT,connectHandler);
_sock.addEventListener(Event.CLOSE,closeHandler);
_sock.addEventListener(ProgressEvent.SOCKET_DATA,socketDataHandler);
_sock.addEventListener(Event.COMPLETE,completeHandler);
_sock.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function(e:S ecurityErrorEvent):void{trace("security error");});
_sock.addEventListener(IOErrorEvent.IO_ERROR,function(e:IOErrorEvent) :void{trace("io error");});
internal function connectHandler(event:Event):void {
trace("Connect...Ok");
//HTTP Request Header
var header:String = "GET "+_url+" HTTP/1.1\r\n";
header += "Accept: */* \r\n"
header += "Accept-Language: zh-cn \r\n";
header += "User-Agent: Mozilla/4.0 \r\n";
header += "Host: " + _host+":"+_port + " \r\n";
header += "Connection: Keep-Alive \r\n";
header += "Cache-Control: no-cache \r\n\r\n";
//write header string
_sock.writeUTFBytes(header);
_sock.flush();
}
internal function socketDataHandler(event:ProgressEvent):void {
//trace("socketDataHandler:"+event.bytesLoaded);
var data:String = _sock.readUTFBytes(_sock.bytesAvailable);
trace(data);
}
Outputs:
HTTP/1.1 302 Moved Temporarily
Date: Tue, 24 Apr 2012 07:25:35 GMT
Server: Apache-Coyote/1.1
Location: http://61.147.88.128/3/345/281/000
Content-Length: 0
X-Via: 1.1 nh227:9090 (Cdn Cache Server V2.0)
Connection: keep-alive
Finally, I got the 302 status, but I have some "sandbox" issue to solve.
Thanks.
North America
Europe, Middle East and Africa
Asia Pacific