java代码获取重定向后的链接

public static void main(String[] args) throws IOException {
    String path = "https://www.baidu.com";
    HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
    conn.setInstanceFollowRedirects(false);
    conn.setConnectTimeout(5000);
    System.out.println(conn.getHeaderField("Location"));
}

 

你可能感兴趣的:(java,java)