设置使用HttpURLConnection时遵循的最大服务器重定向数 [英] Set maximum number of server redirects followed when using HttpURLConnection
本文介绍了设置使用HttpURLConnection时遵循的最大服务器重定向数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用HttpURLConnection时是否有一种方法可以强制执行最大数量的重定向?
Is there a way to mandate the maximum number of redirects that are followed when using HttpURLConnection?
HttpURLConnection conn = (HttpURLConnection) uri.getURI().toURL();
conn.connect();
我只能看到启用/禁用重定向的选项
I can only see an option to enable/disable redirects
conn.setFollowRedirects(true)
我想将最大跟随次数设置为3(似乎默认值是20),以防止出现类似这样的异常:
I want to set a max follow of 3 (it seems the default is 20), to prevent exceptions like this:
java.net.ProtocolException: Server redirected too many times (20)
是由某些服务器上的循环重定向引起的.
that are caused by circular redirects on some servers.
推荐答案
您可以尝试 System.setProperty("http.maxRedirects", "3");
这篇关于设置使用HttpURLConnection时遵循的最大服务器重定向数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文