我通过PowerShell调用webservice GET方法,如下所示:
$result = Invoke-WebRequest -Uri https://localhost/MyApi/Foo/blahA/blahB?three=testing&four=2015-09-18T06:45:29.5199432Z
然而,这给了我以下错误:
不允许使用与号(&)字符。 &运营商留作将来使用;用一个&符号括起来 引号("&")将其作为字符串的一部分传递。
- 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" }
);
答案 0 :(得分:7)
一些事情,你应该用双引号包装你的URI:
$result = Invoke-WebRequest -Uri "https://localhost/MyApi/Foo/blahA/blahB?three=testing&four=2015-09-18T06:45:29.5199432Z"
其次,您的网址一般看起来不对,请尝试
$result = Invoke-WebRequest -Uri "https://localhost/MyApi/Foo?one=blahA&two=blahB&three=testing&four=2015-09-18T06:45:29.5199432Z"