gpt4 book ai didi

rest - 在此处字符串 header 之后但在行尾之前不允许使用任何字符

转载 作者:行者123 更新时间:2023-12-01 19:35:26 27 4
gpt4 key购买 nike

我使用它作为我的脚本的基础:

https://www.nwcadence.com/blog/vststfs-rest-api-the-basics-and-working-with-builds-and-releases

我的脚本如下

Param(
[string]$vstsAccount = "abc",
[string]$projectName = "abc",
[string]$user = "",
[string]$token = "xyz"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$verb = "POST"


$body = @"{

"definition": {
"id": 20
}
}"@


$uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$($projectName)/_apis/build/builds?api-version=4.1"
$result = Invoke-RestMethod -Uri $uri -Method $verb -ContentType "application/json" -Body (ConvertTo-Json $body) -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

但是我在上面的博客文章中使用的主体定义存在语法错误。
> o characters are allowed after a here-string header but before the end
> of the line. At C:\Users\abc\Documents\vstsqueuebuild.ps1:18 char:17
> + "definition": {
> + ~ Unexpected token ':' in expression or statement. At C:\Users\abc\Documents\vstsqueuebuild.ps1:19 char:14
> + "id": 20
> + ~ Unexpected token ':' in expression or statement. At C:\Users\anc\Documents\vstsqueuebuild.ps1:21 char:1
> + }"@
> + ~ Unexpected token '}' in expression or statement. At C:\Users\abc\Documents\vstsqueuebuild.ps1:24 char:9
> + $uri = "https://$($vstsAccount).visualstudio.com/DefaultCollection/$( ..

最佳答案

有多种方法可以更改此处字符串($body 变量的值):

选项1:

$body = @{
definition = @{
id = 20
}
}

选项 2:
$body = @"
{

"definition": {
"id": 20
}
}
"@

正如boxdog所提到的。

选项 3:
$body = '
{

"definition": {
"id": 20
}
}
'

关于rest - 在此处字符串 header 之后但在行尾之前不允许使用任何字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50482528/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com