private String getRedirectUrl(String urlStr) throws IOException { HttpURLConnection.setFollowRedirects(false); URL url = new URL(urlStr); URLConnection conn = url.openConnection(); String location = conn.getHeaderField("Location"); HttpURLConnection.setFollowRedirects(true); return location; } }