我正在做的是使用Jsoup来解析WordPress download-monitor url形式的下载URL。 示例:http:// ** .com / wp-content / plugins / download-monitor / download.php?id = 11036当您单击此链接时,它将打开一个新的下载页面使用id 11036下载真实文件。
我的问题是如何绕过下载监控插件并获取真正的文件网址?
更新1: 这是用于重定向的java代码。
<script type="text/javascript">
console.log(location.href);
var hasAutoDonload = false;
var address;
if(location.href.indexOf("d3") > 0){
address = "http://d3.apknew.com/download.php" + window.location.href.replace("http://apknew.com/download-page","");
}else{
address = "http://d2.apknew.com/download.php" + window.location.href.replace("http://apknew.com/download-page","");
}
var hasTouch = 'ontouchstart' in window;
window.onload = function(){
if(!hasAutoDonload){
downloadFun();
}
}
function downloadFun(){
hasAutoDonload = true;
if(hasTouch){
window.location.href = address;
}else{
document.getElementById("downloadIframe").src = address;
}
}
function downloadFun1(){
window.open(address)
}
//http://d2.apknew.com/download.php?i=er59f9t&n=QuickPic_2.0%20beta.apk&d=2012-02
</script>
答案 0 :(得分:2)
java.lang.CharSequence uri = "<your_url>";
java.net.URL url = new java.net.URL(uri.toString());
java.net.HttpURLConnection httpURLConnection = (java.net.HttpURLConnection) url.openConnection();
httpURLConnection.setInstanceFollowRedirects(false);
httpURLConnection.connect();
int responseCode = httpURLConnection.getResponseCode();
Log.i("Response Code", responseCode);
String header = httpURLConnection.getHeaderField("Location");
Log.i("Final URL", header);
在此处,最终的网址存储在header
中。确保在您提供的URL中包含协议。另外,我用301重定向进行了测试。不确定它是否适用于javascript或其他重定向。