Powershell 使用TeamCity REST API更新值时不支持的媒体类型

Powershell 使用TeamCity REST API更新值时不支持的媒体类型,powershell,teamcity,teamcity-9.0,Powershell,Teamcity,Teamcity 9.0,我有一个Powershell脚本,用于同步各种项目参数。我用于更新项目参数的相关代码是: $propName = "ReleaseNumber" $propValue = "10.0" Invoke-RestMethod -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -Body "$propValue" 升级到TeamCity 9.1后,我在使用脚本时开始收到以

我有一个Powershell脚本,用于同步各种项目参数。我用于更新项目参数的相关代码是:

$propName = "ReleaseNumber"
$propValue = "10.0"
Invoke-RestMethod -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -Body "$propValue"
升级到TeamCity 9.1后,我在使用脚本时开始收到以下错误:

Invoke RestMethod:远程服务器返回错误:(415)不支持的媒体类型


解决此问题需要做什么?

默认情况下,由Powershell的
调用RestMethod
发送的
ContentType
应用程序/x-www-form-urlencoded
。在TeamCity 9.1之前,TeamCity似乎不太关心项目相关API调用的
ContentType
,但在9.1和中,TeamCity似乎对内容类型更加挑剔。因此,由于属性值只是纯文本,要解决此问题,请将
text/plain
指定为
ContentType
,如下所示:

Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"

默认情况下,Powershell的
调用RestMethod
发送的
ContentType
application/x-www-form-urlencoded
。在TeamCity 9.1之前,TeamCity似乎不太关心项目相关API调用的
ContentType
,但在9.1和中,TeamCity似乎对内容类型更加挑剔。因此,由于属性值只是纯文本,要解决此问题,请将
text/plain
指定为
ContentType
,如下所示:

Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"