java.net.ProtocolException: Server redirected too many times

 网页爬虫时,原来正常的代码,可能是因为网站做了cookie校验处理,报异常:java.net.ProtocolException: Server redirected too many times 

表示没有检查到cookie,一直循环重定向。

 在代码中加入蓝色的代码解决:

CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
URL realUrl= new URL(url); 
con = (HttpURLConnection) realUrl.openConnection();

posted on 2018-01-27 22:33  lui  阅读(957)  评论(0编辑  收藏  举报