gpt4 book ai didi

c# - 通过 PowerShell 将多个查询参数传递给 WebService

转载 作者:行者123 更新时间:2023-11-30 14:08:51 25 4
gpt4 key购买 nike

我像这样通过 PowerShell 调用网络服务 GET 方法:

$result = Invoke-WebRequest -Uri https://localhost/MyApi/Foo/blahA/blahB?three=testing&four=2015-09-18T06:45:29.5199432Z

但是,这给了我以下错误:

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

  • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
  • FullyQualifiedErrorId : AmpersandNotAllowed

如果重要的是我的 WebAPI 代码和路由(该方法有两个必需参数和 3 个可选参数):

[HttpGet, ActionName("Foo")]
public string Foo(string one, string two,
string three = null, DateTime? four = null, int five = null)
{
//do stuff
//return some string
}
...
routes.MapHttpRoute(
name: "Foo",
routeTemplate: "Foo/{one}/{two}",
defaults: new { controller = "Testing", action = "Foo" }
);

最佳答案

一些事情,您应该将您的 URI 括在双引号中:

$result = Invoke-WebRequest -Uri "https://localhost/MyApi/Foo/blahA/blahB?three=testing&four=2015-09-18T06:45:29.5199432Z"

其次,你的url一般看起来不对,试试

$result = Invoke-WebRequest -Uri "https://localhost/MyApi/Foo?one=blahA&two=blahB&three=testing&four=2015-09-18T06:45:29.5199432Z"

关于c# - 通过 PowerShell 将多个查询参数传递给 WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049408/

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