读书人

应用URLConnection获取页面内容时对有

发布时间: 2012-10-15 09:45:25 作者: rapoo

使用URLConnection获取页面内容时对有302等跳转的处理

private static URLConnection reload(URLConnection uc) throws Exception {        HttpURLConnection huc = (HttpURLConnection) uc;                if (huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP         || huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM)// 302, 301        return reload(new URL(huc.getHeaderField("location")).openConnection());                return uc;}

?

运用:获取页面内容时,对于http跳https,以及多层跳转,需要做此类处理。

?

读书人网 >编程

热点推荐