【问题标题】:(spring-boot) http to https redirect, 405 method not allow message(spring-boot) http 到 https 重定向,405 方法不允许消息
【发布时间】:2018-03-27 15:56:23
【问题描述】:

我在 AWS 中使用 Spring Boot 和 http 到 https 重定向,使用的是弹性 beanstalk。
所以我请求http然后重定向https,并通过https协议重新请求......
在 https 中,一切正常,
但是在 http 中,get 方法(在控制器中)可以,但是 post 方法不行...
{ "timestamp": 1508137623531, "status": 405, "error": "Method Not Allowed", "exception": "org.springframework.web.HttpRequestMethodNotSupportedException", "message": "Request method 'GET' not supported", "path": "/api/test" }

我的控制器代码
@PostMapping(value = "/test") public String test(@RequestBody String name) { return "hello, " + name; }

我试过this answer,但对我没有帮助...

我该如何解决它...?

【问题讨论】:

    标签: amazon-web-services spring-mvc redirect spring-boot amazon-elastic-beanstalk


    【解决方案1】:

    候补律师

    这是 web 服务器(nginx、apache 等)的问题,而不是 spring boot。
    我使用301重定向,但是301从post改为get。
    所以,我必须使用 308 而不是 301。
    308 不允许从 post 更改为 get,
    但弹性豆茎使用 nginx v1.12.1
    而1.12.1不支持308,1.13.0 support 308

    所以我应该更新 nginx...

    【讨论】:

    • 我在 POST 调用中遇到了同样的问题。你能通过更新nginx来解决它吗?不过不确定它是否可扩展,因为 nginx 1.13.x 在主线上,而亚马逊似乎只支持 1.12.x 和 Beanstalk 的稳定通道。使用 EmbeddedServletContainerFactory 也没有帮助。
    • @testphreak 我没有更新,因为它似乎不能正常工作,所以我使用 307 临时重定向
    • 如果我使用 307,则允许基于 http 和 https 的 POST 调用。我的期望是,如果您使用 HTTP 进行 POST API 调用,它将重定向到 HTTPS。这是一个错误的期望吗?在 /etc/nginx/conf.d/elasticbeanstalk/00_application.conf 中,我添加了` ...... if ($http_x_forwarded_proto != "https") { set $redirect 1; } if ($redirect = 1) { 返回 307 https://$host$request_uri; } ...... ` 之后我在实例上重新启动了 NGINX。不适合我。
    猜你喜欢
    • 2017-06-25
    • 2015-07-22
    • 2018-07-15
    • 2016-03-02
    • 2016-09-23
    • 2014-12-26
    • 2012-09-30
    • 2021-12-12
    • 1970-01-01
    相关资源
    最近更新 更多