如何下载使用WordPress download-monitor插件重定向的真实文件?

时间:2012-10-18 17:53:52

标签: android wordpress redirect plugins download

我正在做的是使用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&#038;n=QuickPic_2.0%20beta.apk&#038;d=2012-02
</script>

1 个答案:

答案 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或其他重定向。