首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-10-15 
使用URLConnection获取页面内容时对有302等跳转的处理private static URLConnection reload(URLConnection

使用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,以及多层跳转,需要做此类处理。

?

热点排行