2

我正在做的是使用 Jsoup 来解析 WordPress 下载监视器 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>
4

1 回答 1

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);

在这里,最终的 URL 存储在header. 确保在您提供的 URL 中包含协议。另外,我已经用 301 重定向测试了这个。不确定它是否适用于 javascript 或其他重定向。

于 2012-10-18T18:09:12.383 回答