httpclient中出现CircularRedirectException异常分析
假如我们有三个url如下:
A: http://www.domain1.com
B: http://www.domain2.com
C: http://www.domain2.com/test
其中B和C的host是一样的
我们通过httpclient请求A,A需要重写向到B,但B又需要重定向到C,这个时候就会出现CircularRedirectException的异常
private boolean isRedirectNeeded(final HttpMethod method) { switch (method.getStatusCode()) { case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_SEE_OTHER: case HttpStatus.SC_TEMPORARY_REDIRECT: LOG.debug("Redirect required"); if (method.getFollowRedirects()) { return true; } else { return false; } default: return false; } //end of switch }