How to detect a redirected URL?

前端 未结 2 563
无人共我
无人共我 2021-01-26 17:57

I\'m working on an app that takes URLs from RSS feeds and opens them in a video player. It works if the URL is directly to the mp4/whatever file, but if I have a redirected URL

相关标签:
2条回答
  • 2021-01-26 18:08

    for redirected url you may try this

    try {
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY){
            String location = response.getHeaders("Location")[0].toString();
            String redirecturl = location.replace("Location: ", "");
        }
    }
    
    0 讨论(0)
  • 2021-01-26 18:22

    I made a test for you with my firefox10:
    I typed your non-redirected url in my browser, and it will show the download page very soon, but for the redirected url, I aslo have to wait for a while to see the download page(more than 10s). So I guess accessing redirected url is much slower than the non-redirected one.

    0 讨论(0)
提交回复
热议问题