http请求获取跳转后URL JAVA

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class TestUrl {
    public static void main(String[] args) {
        try {
            String testUrl="https://s.click.taobao.com/hCUhcXw?pid=mm_0_0_0";//原始链接
            URL Url = new URL(testUrl);
            HttpURLConnection conn=(HttpURLConnection)Url.openConnection();
            conn.getResponseCode();
            String realUrl=conn.getURL().toString();//跳转后所返回的链接
            System.out.println(realUrl);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
http请求获取跳转后URL JAVA

你可能感兴趣的:(java)