【发布时间】:2018-07-25 05:51:50
【问题描述】:
我正在使用 spring-boot-starter-actuator:2.0.0.RELEASE 并启用了以下功能:
management.endpoint.shutdown.enabled=true
management.endpoints.web.exposure.include=shutdown
management.security.basic.enabled=false
通过 PowerShell 命令,我调用了 shutdown 端点:
$endpointUrl = "http://localhost:8200/actuator/shutdown"
Invoke-WebRequest -Uri $endPointUrl -Method POST
我得到了:
Invoke-WebRequest : The remote server returned an error: (415).
At line:1 char:1
+ Invoke-WebRequest -Uri $endPointUrl -Method POST
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
在我的WebSecurityConfigurerAdapter 中,我有:
http
.authorizeRequests()
.csrf()
.disable();
我的 Web 请求调用出了什么问题?
【问题讨论】:
-
错误 415 是“不支持的媒体类型”。我想难怪你正在做一个没有正文的 POST
-
@Theo 我尝试了一个身体并得到了相同的
415。执行器端点shutdown只能通过 POST 调用。我认为它不需要任何参数 -
我只能找到确实使用了 POST 的 cUrl 命令,但也找不到
-X参数。但是,我还在 StackOverflow 上找到了这个答案,它可能会回答你的问题:stackoverflow.com/questions/48192765/… -
@Theo 我试过了,它实际上在 Linux 环境中工作......但是在 Windows 命令行上,它出现了这个错误......而且,这只发生在版本
2.0.0+,以前我在另一个项目中使用了1.5+,我可以用上面的PowerShell脚本很好地关闭 -
hummmm.. 那时我想我不能帮你。
-X似乎将 curl 命令的行为从 POST 更改为其他内容。-i告诉它在输出中包含标头,因此在 Powershell 中您可能需要执行类似Invoke-WebRequest -Uri $endPointUrl -Method Head的操作??
标签: powershell spring-boot spring-boot-actuator