Redirect SpringBoot Undertow将POST从HTTP重定向到HTTPS

Redirect SpringBoot Undertow将POST从HTTP重定向到HTTPS,redirect,spring-boot,undertow,Redirect,Spring Boot,Undertow,我读过StackOverflow上的那些帖子: 我想将Undertow配置为使用GET和POST从HTTP重定向到HTTPS。GET可以工作,但在发布时,它会查找具有相同URL的GET方法(在我的例子中,它会找到) 我的服务器配置: @Configuration public class UndertowConfig { @Bean public EmbeddedServletContainerFactory undertow() { UndertowEm

我读过StackOverflow上的那些帖子:

我想将Undertow配置为使用GET和POST从HTTP重定向到HTTPS。GET可以工作,但在发布时,它会查找具有相同URL的GET方法(在我的例子中,它会找到)

我的服务器配置:

@Configuration
public class UndertowConfig {

    @Bean
    public EmbeddedServletContainerFactory undertow() {
        UndertowEmbeddedServletContainerFactory undertow = new   UndertowEmbeddedServletContainerFactory();
        undertow.addBuilderCustomizers(builder -> builder.addHttpListener(8080, "0.0.0.0"));
        undertow.addDeploymentInfoCustomizers(deploymentInfo -> {
            deploymentInfo.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
            .addUrlPattern("/*"))
            .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
            .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
                .setConfidentialPortManager(exchange -> 8443);
        });
        return undertow;
    }
}
强制HTTPS:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requiresChannel().anyRequest().requiresSecure();
    }
}
控制器:

@RestController
public class HelloController {

    @RequestMapping("/")
    public String get() {
        return "GET";
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String post() {
        return "POST";
    }

}
客户:

public class Client {

    public static void main(String[] args) {

        HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);

        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        HttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).setSSLHostnameVerifier((hostname, session) -> true).build();
        factory.setHttpClient(httpClient);
        RestTemplate restTemplate = new RestTemplate(factory);
        String get = restTemplate.getForObject("http://localhost:8080/", String.class);
        ResponseEntity<String> post = restTemplate.postForEntity("http://localhost:8080/", null, String.class);
}
公共类客户端{
公共静态void main(字符串[]args){
HttpsURLConnection.setDefaultHostnameVerifier((主机名,会话)->true);
HttpComponents客户端HttpRequestFactory工厂=新的HttpComponents客户端HttpRequestFactory();
HttpClient HttpClient=HttpClientBuilder.create().setRedirectStrategy(新的LaxRedirectStrategy()).setSSLHostnameVerifier((主机名,会话)->true.build();
工厂设置httpClient(httpClient);
RestTemplate RestTemplate=新的RestTemplate(工厂);
字符串get=restTemplate.getForObject(“http://localhost:8080/“,String.class);
ResponseEntity post=restTemplate.postForEntity(“http://localhost:8080/,null,String.class);
}
}


如何使POST请求进入POST?

您找到解决方案了吗?给您。。。