Powershell 使用POST请求调用Spring Boot Actuator 2.0.0 ShutDown endpoint时返回错误415

Powershell 使用POST请求调用Spring Boot Actuator 2.0.0 ShutDown endpoint时返回错误415,powershell,spring-boot,spring-boot-actuator,Powershell,Spring Boot,Spring Boot Actuator,我正在使用弹簧启动启动器执行器:2.0.0。在启用以下功能的情况下释放: management.endpoint.shutdown.enabled=true management.endpoints.web.exposure.include=shutdown management.security.basic.enabled=false 在PowerShell命令中,我使用以下命令调用了shutdown端点: $endpointUrl = "http://localhost:8200/actu

我正在使用
弹簧启动启动器执行器:2.0.0。在启用以下功能的情况下释放

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
在我的
网站安全配置适配器中,我有:

http
    .authorizeRequests()
    .csrf()
    .disable();

我的Web请求调用有什么问题?

调用Web请求中的默认内容类型是
application/x-www-form-urlencoded

见:

-内容类型 指定web请求的内容类型。如果省略此参数且请求方法为POST,则Invoke WebRequest会将内容类型设置为application/x-www-form-urlencoded。否则,不会在调用中指定内容类型

我在Postman中尝试了
shutdown
endpoint使用
application/json
或根本不使用ContentType头(在Spring文档中没有找到)。但将此标题设置为
application/json
()可能会出现一些问题
因此,可能只需尝试将
-ContentType'application/json'-Body设置为“null”
。我没有Windows计算机可以尝试。

错误415是“不支持的媒体类型”。我想这并不奇怪,因为你在做一篇没有广告的文章body@Theo我试着用一具尸体,得到了同样的
415
。执行器端点
关闭
只能通过POST调用。我不认为它期望任何paramsI只能在确实使用POST的地方找到cUrl命令,而且还会找到
-X
参数。然而,我在StackOverflow上也找到了这个答案,这可能会回答你的问题:@Theo我试过了,它实际上在Linux环境下工作。。。但是在Windows命令行中,它有一个错误。。。此外,这只发生在版本
2.0.0+
中,之前我在另一个项目中使用了
1.5+
,我可以使用PowerShell脚本很好地关闭。。那我想我帮不了你。
-X
似乎将curl命令的行为从POST更改为其他方式。
-i
告诉它在输出中包含标题,因此在Powershell中,您可能需要执行类似于
调用WebRequest-Uri$endPointUrl-Method Head
的操作??嘿,添加
-ContentType“application/json”
可以工作!它不需要
-Body“null”
。非常感谢