WebApi 放上去,params怎么传?
WebApi Put, how pass the params?
我创建了一个自动为我创建 som 方法的 webApi。
Put-Method 是这样创建的:
// PUT: api/Actor/5
[ResponseType(typeof(void))]
public async Task<IHttpActionResult> PutActor(int id, Actor actor)
{
//Code that updates the actor
}
但是我该如何调用这个方法呢?
我认为它必须以:
开头
HttpResponseMessage response = client.PutAsJsonAsync("api/Actors/") <-How can i add the two params?
根据一些帖子,如果没有解决方法,您将无法做到:
WebAPI Multiple Put/Post parameters
但考虑到该方法是自动为我创建的,这似乎很奇怪。应该是标准方法吗?
您可以在路由中传递 id
,而有效负载中的 Actor 使用 following overload
将对象作为第二个参数:
HttpResponseMessage response = client.PutAsJsonAsync("api/Actors/123", new
{
actor = new Actor
{
Name = "John Smith",
Age = 30,
}
});
我创建了一个自动为我创建 som 方法的 webApi。 Put-Method 是这样创建的:
// PUT: api/Actor/5
[ResponseType(typeof(void))]
public async Task<IHttpActionResult> PutActor(int id, Actor actor)
{
//Code that updates the actor
}
但是我该如何调用这个方法呢? 我认为它必须以:
开头HttpResponseMessage response = client.PutAsJsonAsync("api/Actors/") <-How can i add the two params?
根据一些帖子,如果没有解决方法,您将无法做到:
WebAPI Multiple Put/Post parameters
但考虑到该方法是自动为我创建的,这似乎很奇怪。应该是标准方法吗?
您可以在路由中传递 id
,而有效负载中的 Actor 使用 following overload
将对象作为第二个参数:
HttpResponseMessage response = client.PutAsJsonAsync("api/Actors/123", new
{
actor = new Actor
{
Name = "John Smith",
Age = 30,
}
});