shiftins
shiftins

Reputation: 97

How to get HTTP Status Code from AS3 NetStream Object?

I'm trying to distinguish specifically between the 404 and 401 (or any) HTTP status codes, but the events raised by NetStream/NetConnect do not seem to include the HTTP status.

var url = "404_or_401_producing_url";

var _nc = new NetConnection(); 
_nc.connect(null);

var _ns = new NetStream(_nc);
_ns.play(url);

Is there an event or property available during this flow that includes the HTTP status?

Upvotes: 0

Views: 215

Answers (2)

akmozo
akmozo

Reputation: 9839

To get HTTP status code, I recommand you to use URLStream instead of NetStream which dont use a HTTPStatusEvent. For more details, take a look here (links from adobe) : URLStream and HTTPStatusEvent. And after verify the HTTP status, you can use or not NetStream to play your stream.

Upvotes: 0

user773737
user773737

Reputation:

NetConnection/NetStatus doesn't work that way. It's meant to connect to RTMP servers, which don't throw 4xx status codes. You can, however, create an event listener.

connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

private function netStatusHandler(event:NetStatusEvent):void {
    switch (event.info.code) {
        case "NetConnection.Connect.Success":
            connectStream();
        break;
        case "NetStream.Play.StreamNotFound":
             trace("Stream not found: " + videoURL);
        break;
     }
 }

There are a whole bunch of status codes to listen to, but none of them are 4xx errors

Upvotes: 2

Related Questions