I am using spring-boot-starter-actuator:2.0.0.RELEASE
with the following enabled:
management.endpoint.shutdown.enabled=true
management.endpoints.web.exposure.include=shutdown
management.security.basic.enabled=false
From PowerShell command, I invoked the shutdown
endpoint with:
$endpointUrl = "http://localhost:8200/actuator/shutdown"
Invoke-WebRequest -Uri $endPointUrl -Method POST
and I got:
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
In my WebSecurityConfigurerAdapter
, I have:
http
.authorizeRequests()
.csrf()
.disable();
What's wrong with my Web request call?
Default ContentType in Invoke-WebRequest
is 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.
I tried in Postman and shutdown
endpoint works with application/json
or without ContentType header at all (didn't find this in Spring documentation). But looks like there might be some issues with setting this header to application/json
(https://github.com/PowerShell/PowerShell/issues/3131)
So probably just try to set -ContentType 'application/json' -Body "null"
. I don't have Windows machine to try.