从输出中,我了解到网站主页确实刷新并将请求重定向到在浏览器上正常但在代码上没有的其他页面。那么我该如何与重定向一起前进呢?
try {
URL url = StringUtils.stringToURL(link);
URLConnection dbGatewayURL = url.openConnection();
dbGatewayURL.setConnectTimeout(timeout);
BufferedReader in = new BufferedReader(new InputStreamReader(
dbGatewayURL.getInputStream()));
StringBuffer responseData = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null) {
responseData.append(line + "\n");
}
输出是:
<HEAD>
<META HTTP-EQUIV=REFRESH CONTENT="0;URL=/sites/engbm">
</HEAD>
当我尝试时,这会引发意外的文件结束异常httpUrlConn.setRequestMethod("HEAD");