How to get redirect url on blackberry

假如想象 提交于 2019-12-12 03:10:09

问题


I play a video url using streaming player on blackberry. If the url returns "200" status code it play successfully.

When i pass the below url, it returns "302" http status code.It won't play on streaming player.

http://belointr.rd.llnwd.net/KGW/ea398ac7b03a91c2ddf451f1fd7e3ef87f19da59_fl9.mp4?x-belo-vsect=kgw-basketball

When i check the statuscode for 302 its says redirect url.

When i pass the url on browser, it calls automatically below the redirect url.

http://belointr.vo.llnwd.net/kip0/_pxn=2+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxI1=A21907+_pxL1=begin+_pxM1=+_pxR1=13737+_pxK=20558/KGW/ea398ac7b03a91c2ddf451f1fd7e3ef87f19da59_fl9.mp4?x-belo-vsect=kgw-basketball

How can i get the redirect url programatically on blackberry.?

pls help me.


回答1:


In the headers of the response, retrieve the value of the header 'Location', it contains the redirect url. This is standard in HTTP protocol

Edit: Real quick sample on how to get the location header (could be written a lot better and safer)

    URL url = new URL("http://some.url");
    int responseCode = -1;
    while (responseCode != 200) {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        responseCode = conn.getResponseCode();
        if (responseCode > 299 && responseCode < 400) {
            url = new URL(conn.getHeaderField("Location"));
        }
    }


来源:https://stackoverflow.com/questions/9500003/how-to-get-redirect-url-on-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!