Follow 302 redirect using Spring restTemplate?

前端 未结 3 828
庸人自扰
庸人自扰 2020-12-06 16:19
  RestTemplate restTemplate = new RestTemplate();

  final MappingJackson2XmlHttpMessageConverter converter = new MappingJackson2XmlHttpMessageConverter();
  final L         


        
3条回答
  •  一个人的身影
    2020-12-06 16:37

    Are you trying to redirect from one protocol to another, e.g. from http to https or vise versa? If so the automatic redirect won't work. See this comment: URLConnection Doesn't Follow Redirect

    After discussion among Java Networking engineers, it is felt that we shouldn't automatically follow redirect from one protocol to another, for instance, from http to https and vise versa, doing so may have serious security consequences

    from https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4620571

    Otherwise if you debug the RestTemplate code you will see that by default HttpURLConnection is set properly with getInstanceFollowRedirects() == true.

提交回复
热议问题