我有一个名为后端(端口: 9090)的服务,位于Zuul后面(端口: 8080)。
浏览器在Zuul上调用一个GET方法,该方法执行重定向。
示例调用:http://localhost:8080/testredirect
结果:
预期结果:
Zuul似乎正在返回200,因为它是一个代理服务器,因此隐藏了重定向。
在服务器端的GET方法中定义URL时,如何在浏览器中实现302重定向?
下面是后端服务:
@SpringBootApplication
public class BackendApplication {
@RestController
@RequestMapping
public class Backend {
@GetMapping(value = "/hello")
public String sayHello() {
return "Hello world";
}
@GetMapping(value = "/testredirect")
public RedirectView sayRandom() {
return new RedirectView("/hello");
}
public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}
}
}以下是Zuul的配置:
server:
port: 8080
zuul:
routes:
core:
sensitive-headers:
path: /core/**
url: http://localhost:9090/注:弹簧云-> Edgware.RELEASE
发布于 2017-12-24 09:21:09
在春季启动版本Edgeware.RELEASE中,功能发生了变化。
在Edgeware.RELEASE:返回200和页面的内容。
在Dalston.SR4:返回302和浏览器重定向。
发布于 2017-12-26 12:29:14
您可以在Spring上下文中定义bean。
@Bean
public ApacheHttpClientFactory apacheHttpClientFactory() {
return new ApacheHttpClientFactory() {
@Override
public HttpClientBuilder createBuilder() {
return HttpClientBuilder.create()
.disableContentCompression()
.disableCookieManagement()
.useSystemProperties()
.disableRedirectHandling();
}
}
}https://stackoverflow.com/questions/47817427
复制相似问题