public static void test_getRedirectUrl() throws Exception {
String url = "http://weixin.sogou.com/websearch/art.jsp?sg=CBf80b2......";
String redictURL = getRedirectUrl(url);
System.out.println(redictURL);
}
/**
获取重定向地址
@param path
@return
@throws Exception
*/
static String getRedirectUrl(String path) throws Exception {
HttpURLConnection conn = (HttpURLConnection) new URL(path)
.openConnection();
conn.setInstanceFollowRedirects(false);
conn.setConnectTimeout(5000);
return conn.getHeaderField("Location");
}
static void main(String[] args) {
try {
test_getRedirectUrl();
} catch (Exception e) {
e.printStackTrace();
}
}