Spring Boot Actuator 2.0.0 ShutDown 端点 returns 使用 POST 请求调用时出现错误 415
Spring Boot Actuator 2.0.0 ShutDown endpoint returns error 415 when invoked with POST request
我正在使用 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 请求调用有什么问题?
Invoke-WebRequest
中的默认 ContentType 是 application/x-www-form-urlencoded
-ContentType
Specifies the content type of the web request. If this parameter is omitted and the request method is POST, Invoke-WebRequest sets the content type to application/x-www-form-urlencoded. Otherwise, the content type is not specified in the call.
我在 Postman 中尝试过,shutdown
端点可以与 application/json
一起使用,或者根本不使用 ContentType header(在 Spring 文档中找不到)。但看起来将此 header 设置为 application/json
(https://github.com/PowerShell/PowerShell/issues/3131) 可能存在一些问题
所以可能只是尝试设置 -ContentType 'application/json' -Body "null"
。我没有 Windows 机器可以尝试。
我正在使用 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 请求调用有什么问题?
Invoke-WebRequest
中的默认 ContentType 是 application/x-www-form-urlencoded
-ContentType Specifies the content type of the web request. If this parameter is omitted and the request method is POST, Invoke-WebRequest sets the content type to application/x-www-form-urlencoded. Otherwise, the content type is not specified in the call.
我在 Postman 中尝试过,shutdown
端点可以与 application/json
一起使用,或者根本不使用 ContentType header(在 Spring 文档中找不到)。但看起来将此 header 设置为 application/json
(https://github.com/PowerShell/PowerShell/issues/3131) 可能存在一些问题
所以可能只是尝试设置 -ContentType 'application/json' -Body "null"
。我没有 Windows 机器可以尝试。