Web APIに次のメソッドがあります
public class AccessPanelController : ApiController
{
public HttpResponseMessage PostGrantAccess([FromUri]GrantAccessRequest grantAccessRequest)
{
var deviceId = grantAccessRequest.DeviceId;
var grantAccessResponse = new GrantAccessResponse()
{
Status = "OK"
};
var response = Request.CreateResponse<GrantAccessResponse>(HttpStatusCode.OK, grantAccessResponse);
return response;
}
}
GrantAccessRequest クラス:
public class GrantAccessRequest
{
public string DeviceId { get; set; }
}
クライアント:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:55208/");
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
Uri uri = null;
var request = new GrantAccessRequest { DeviceId = "bla" };
var response = client.PostAsJsonAsync("api/accesspanel", uri).Result;
if (response.IsSuccessStatusCode)
{
uri = response.Headers.Location;
}
私のPostGrantAccess
メソッドでgrantAccessRequest
は、構築されていますが、DeviceId
nullです