它显然是在无限循环中重定向,因为您无需维护用户会话。会话通常由cookie支持。您需要先创建一个,
cookieManager然后才能使用
URLConnection。
// First set the default cookie manager.cookieHandler.setDefault(new cookieManager(null, cookiePolicy.ACCEPT_ALL));// All the following subsequent URLConnections will use the same cookie manager.URLConnection connection = new URL(url).openConnection();// ...connection = new URL(url).openConnection();// ...connection = new URL(url).openConnection();// ...
也可以看看:
- 使用java.net.URLConnection触发和处理HTTP请求



