Вопрос

I am trying to do a delete to a Web API web service using HTTPClient.

This is simple enough if I simply pass the id of what I need to delete in the uri:

deleteAsync("http://localhost/myService/main/deleteItem?id=1234567")

but if I want to pass back a complex type on delete, can I pass back that object as json in the body of the request and the access it from the service using [FromBody]? How would I accomplish something like this?

Это было полезно?

Решение

You could use httpPost to post your complex object to your delete method.

E.g.

[System.Web.Http.AcceptVerbs("Post")]
public HttpResponseMessage DeleteComplexObject(Models.ComplexObject deleteme)
{
    this.ComplexObjectService.Delete(deleteme);
    var response = Request.CreateResponse(HttpStatusCode.Accepted);

    return response;
}

Here model binding is used to convert your json object into the ComplexObject automatically so you don't need to use [FromBody]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top