我有以下模型
public class Customer
{
public string Name
{
get;set;
}
public string Address
{
get;
set;
}
}
以下WebAPI方法
[Route("PostCustomer")]
[HttpPost]
public Customer PostCustomer([FromBody]Customer c)
{
return c;
}
以下客户端代码
Customer cust = new Customer() { Name = "abcd", Address = "test" };
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:11581");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsJsonAsync<Customer>("api/values/PostCustomer", cust);
WebAPI方法永远不会被调用,我从Web API获得的响应没有内容。当我尝试相同的获取它工作正常。