使用 TeamCity REST 更新值时不支持的媒体类型 API
Unsupported Media Type when updating values using the TeamCity REST API
我有一个用于同步各种项目参数的 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 : The remote server returned an error: (415) Unsupported Media Type.
我需要做什么来解决这个问题?
默认情况下,Powershell的Invoke-RestMethod
发送的ContentType
是application/x-www-form-urlencoded
。在 TeamCity 9.1 之前,TeamCity 似乎不太关心与项目相关的 API 调用的 ContentType
,但是对于 9.1 和 addition of both XML and JSON payloads,TeamCity 似乎正在对内容类型更挑剔。因此,由于您的 属性 值只是纯文本,要解决此问题,请将 text/plain
指定为 ContentType
,如下所示:
Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"
我有一个用于同步各种项目参数的 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 : The remote server returned an error: (415) Unsupported Media Type.
我需要做什么来解决这个问题?
默认情况下,Powershell的Invoke-RestMethod
发送的ContentType
是application/x-www-form-urlencoded
。在 TeamCity 9.1 之前,TeamCity 似乎不太关心与项目相关的 API 调用的 ContentType
,但是对于 9.1 和 addition of both XML and JSON payloads,TeamCity 似乎正在对内容类型更挑剔。因此,由于您的 属性 值只是纯文本,要解决此问题,请将 text/plain
指定为 ContentType
,如下所示:
Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"