【问题标题】:Spring Boot "Request method 'GET' not supported" while redirecting POST request to https port through Catalina ConnectorSpring Boot“不支持请求方法'GET'”,同时通过Catalina连接器将POST请求重定向到https端口
【发布时间】:2017-01-24 12:25:47
【问题描述】:

我正在尝试通过我的 Spring Boot 应用程序中的 Catalina 连接器将 http 重定向到 https。如果传入的 POST 请求是“https”,那么它按预期工作。但是,如果我传入的 POST 请求是“http”并且在通过下面的代码重定向到“https”之后,它会在某个地方更改为 GET,因为我得到了 -

WARN 45028 --- [nio-8443-exec-8] o.s.web.servlet.PageNotFound:不支持请求方法“GET”

以下是我的@SpringBootApplication 类中的方法:

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(org.apache.catalina.Context context) {
          SecurityConstraint securityConstraint = new SecurityConstraint();
          securityConstraint.setUserConstraint("CONFIDENTIAL");
          SecurityCollection collection = new SecurityCollection();
          collection.addPattern("/*");
          securityConstraint.addCollection(collection);
          context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
 }

private Connector initiateHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setPort(10024);
    connector.setSecure(false);
    connector.setRedirectPort(8443);

    return connector;
 }

【问题讨论】:

  • 这个你搞定了吗?我有同样的问题。

标签: spring-mvc ssl https catalina embedded-tomcat-7


【解决方案1】:

在代码中的postProcessContext() 覆盖方法中添加collection.addMethod(DEFAULT_PROTOCOL); 这一行。 它适用于所有 HTTP 请求方法,如 POST,PUT,DELETE,GET 等。

【讨论】:

  • 什么是DEFAULT_PROTOCOL?
  • 在postProcessContext中添加collection.addMethod("org.apache.coyote.http11.Http11NioProtocol")
  • 这个可以扩展我不确定我是否关注
猜你喜欢
  • 2018-06-03
  • 2020-03-31
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
相关资源
最近更新 更多