我正在尝试使用 Spring endpoints
正常关闭我的应用程序,但出现错误:
2016-08-09 13:46:54.606 WARN 13315 --- [nio-8090-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Handler execution resulted in exception: Request method 'POST' not supported
我正在使用 this指南,我已将我的 application.properties
设置为 endpoints.shutdown.enabled=true
和 endpoints.shutdown.sensitive=false
。我还在我的 build.gradle 中包含了 compile("org.springframework.boot:spring-boot-starter-actuator")
。
当我发送 CURL 请求时:curl -X POST https://localhost:8090/shutdown -k
我从服务器收到以下响应:
{"timestamp":1470747537792,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/shutdown"}
我做错了什么吗?有什么我可能会遗漏的吗?我在整个应用程序中启用了 CSRF,因此无法为我的应用程序禁用它。
最佳答案
您需要将 CSRF token 作为 header 或参数或其他内容发送。你的例子:
curl -X POST https://localhost:8090/shutdown -k
不包含 CSRF token ,因此 Spring 当然会拒绝它。这确实是 CSRF 过滤器的全部要点。您需要决定从该过滤器中排除 /shutdown
uri 是否合适,或者您是否需要提供 token /随机数。
关于java - Spring 正常关闭 - 请求方法不支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851315/