HttpClient的CircularRedirectException异常解决办法

HttpClient的CircularRedirectException解决办法

org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.baidusplider.webbaidusplider.Bingsplidertest.getSearchInfoHtml(Bingsplidertest.java:79)
at com.baidusplider.webbaidusplider.Bingsplidertest.main(Bingsplidertest.java:151)
Caused by: org.apache.http.client.CircularRedirectException: Circular redirect to ‘http://cn.bing.com/search?q=LOL
at org.apache.http.impl.client.DefaultRedirectStrategy.getLocationURI(DefaultRedirectStrategy.java:177)
at org.apache.http.impl.client.DefaultRedirectStrategy.getRedirect(DefaultRedirectStrategy.java:221)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:122)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
… 4 more
处理办法:设置HttpClient参数,在new一个get请求之后写上httpGet.getParams().setParameter(“http.protocol.allow-circular-redirects”, true);
‘http.protocol.allow-circular-redirects’:定义环形重定向(重定向到相同路径)是否被允许。HTTP规范在环形重定向没有足够清晰的允许表述,因此这作为可选的是可以开启的。这个参数期望得到一个java.lang.Boolean类型的值。如果这个参数没有被设置,那么环形重定向就不允许。

猜你喜欢

转载自blog.csdn.net/m0_37737148/article/details/89160442