我使用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请求调用出了什么问题?
答案 0 :(得分:1)
Invoke-WebRequest
中的默认ContentType是application/x-www-form-urlencoded
-ContentType 指定Web请求的内容类型。如果忽略此参数,并且请求方法为POST,则Invoke-WebRequest会将内容类型设置为application / x-www-form-urlencoded。否则,将在呼叫中未指定内容类型。
我在Postman中尝试过,shutdown
端点可以与application/json
一起使用,也可以完全没有ContentType头(在Spring文档中找不到)。但是,将此标头设置为application/json
(https://github.com/PowerShell/PowerShell/issues/3131)可能会出现一些问题
因此可能只是尝试设置-ContentType 'application/json' -Body "null"
。我没有Windows计算机可以尝试。