我在使用 Powershell 将字符串列表传递给 API 方法时遇到了一些困难。
我尝试了什么:我没有尝试什么?我的最新版本是这样的:
$uri = "http://localhost:15207/v1/API/GetFoos"
Add-Type -AssemblyName System.Core
$contents = New-Object System.Collections.Generic.List[string]
$contents.Add('Foo_1')
$contents.Add('Foo_1000002')
$body = @{
"someParam"="string1"
"contents"= $contents
}
Invoke-RestMethod -uri $uri -Body $body -Method Post
这会导致 API 接收到以下值:
[0] = "Foo_1 Foo_1000002"
但我尝试过数组,以及括号、方括号、单引号和双引号的各种不同组合。在所有情况下,contents 参数要么接收一个对象类型,要么接收一个值,它是我试图传递的值的串联组合。
我确信我不是第一个必须将字符串列表传递给 API 方法的人,但是搜索它包括许多导致不相关匹配的常用术语。