Get rid of the [FromUri] attribute in your controller action. Also on the client, you seem to be doing nothing with the request variable, which contains the payload:
public HttpResponseMessage PostGrantAccess(GrantAccessRequest grantAccessRequest)
To better understand how model binding works in the web API, I recommend that you read the following article .
So:
using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:55208/"); var request = new GrantAccessRequest { DeviceId = "bla" }; var response = client.PostAsJsonAsync("api/accesspanel", request).Result; if (response.IsSuccessStatusCode) { var uri = response.Headers.Location; } }
Note that you do not need to set the Accept request header in this case, because you are using the PostAsJsonAsync method.
Also I don't know if this is a typo in your question, but you seem to have specified api/accesspanel as url, while your controller action is called GrantAccessRequest .
source share