如何检测重定向的URL? [英] How to detect a redirected URL?
本文介绍了如何检测重定向的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,该应用程序从RSS源获取URL并在视频播放器中打开它们。它是有效的,如果URL直接到mp4 /任何文件,但如果我有一个重定向的URL(例如这一个重定向这里)我的播放器崩溃并失败。
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 (e.g. This one which redirects here) my player crashes and fails.
有没有办法检测它的重定向,以及哪个URL ?
Is there any way to detect if its redirecting, and to which URL?
提前致谢:)
推荐答案
重定向的网址你可以试试这个
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: ", "");
}
}
这篇关于如何检测重定向的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文