【问题标题】:Unsupported Media Type when updating values using the TeamCity REST API使用 TeamCity REST API 更新值时不受支持的媒体类型
【发布时间】:2015-08-23 05:07:48
【问题描述】:

我有一个 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) Unsupported Media Type.

我需要做什么来解决这个问题?

【问题讨论】:

    标签: powershell teamcity teamcity-9.0


    【解决方案1】:

    默认情况下,Powershell的Invoke-RestMethod发送的ContentTypeapplication/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"
    

    【讨论】:

      猜你喜欢
      • 2015-06-02
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      相关资源
      最近更新 更多