PUT 更新来自 PostMan 但不是来自 Powershell 脚本的 TeamCity 配置参数

PUT update a TeamCity Configuration Parameter working from PostMan but not from Powershell Script

$url = "https://teamcity.myserver.io/guestAuth/app/rest/buildTypes/id:SandboxPlayGround_WindowsForms1_Build/parameters/Version" 

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"

$headers.Add("Content-Type", 'text/plain')

$headers.Add("Origin", 'https://teamcity.myserver.io')

Invoke-RestMethod -Method Put -Uri $url -Headers $headers -Body "2.3.1.0"

给我错误:

[19:54:59][Step 2/6] Invoke-RestMethod : HTTP Status 405 - Request method 'PUT' not supported
[19:54:59][Step 2/6]
[19:54:59][Step 2/6]
[19:54:59][Step 2/6]
[19:54:59][Step 2/6] type Status report
[19:54:59][Step 2/6] message Request method 'PUT' not supported
[19:54:59][Step 2/6] description The specified HTTP method is not allowed for the requested resource.

但我可以使用来自 PostMan 的相同 URL 和 Headers 更新参数值就好了。 我哪里错了?

您可以使用 C# 使用 FluentTc 库设置构建配置参数:

new RemoteTc()
  .Connect(_ => _.ToHost("teamcity.myserver.io")
    .AsUser("MYUSERNAME", "MYPASSWORD"))
  .SetBuildConfigurationParameters(
    _ => _.Id("SandboxPlayGround_WindowsForms1_Build"),
    _ => _.Parameter("Version", "2.3.1.0") );

如果需要,您可以使用以下技术之一从 Powershell 调用此代码: http://executeautomation.com/blog/calling-c-code-in-powershell-and-vice-versa/