java - 使用带有 GET 的 java.net.URLConnection,如何获取重定向 URL?

标签 java http http-get urlconnection

使用 java.net.URLConnection,在特定 URL 上使用 GET,此特定 URL 将重定向到新页面。我如何从响应中获取新的 URL?

最佳答案

鉴于 Rishal 的链接和 amobiz 的回答是我正在寻找的:

URLConnection con = new URL( url ).openConnection();
System.out.println( "orignal url: " + con.getURL() );
con.connect();
System.out.println( "connected url: " + con.getURL() );
InputStream is = con.getInputStream();
System.out.println( "redirected url: " + con.getURL() );
is.close();

关于java - 使用带有 GET 的 java.net.URLConnection,如何获取重定向 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49491634/

相关文章:

c# - HttpClient 究竟是如何处理超时的?

java - Apache CXF - 以 http 为中心的方法以及从客户端到服务器的 PUT

C++ 相当于Java http请求

java - 从每个表单导航中代号一个新的 gui builder-back 命令

android - 如何解决 SocketException : Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)

java - 如何从java中的YAML文件中读取?

dictionary - 角度 6 : No 'Access-Control-Allow-Origin' header is present on the requested resource

https - HTTP : Why is wrong sending username and password in get request?

java - Android min3d 崩溃

java - OutOfBoundsException 问题,Java