【发布时间】:2016-04-12 05:22:22
【问题描述】:
很难理解 URLConnection 以及可能在哪里隐式调用 connect()。
此代码不起作用:
URL url = new URL(firstUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
conn.getHeaderField("Location"); //returns null
connection.setInstanceFollowRedirects(false);
此代码有效:
URL url = new URL(firstUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setInstanceFollowRedirects(false);
conn.getHeaderField("Location"); //returns the redirect URL
我很难理解这一点。 “getHeaderField”是否隐式调用连接?我在任何地方的文档中都没有看到这一点。
【问题讨论】:
标签: java http url httpurlconnection