我有一个接受个人资料对象的webAPI控制器
public IHttpActionResult CreateProfile([FromBody] Profile request)
配置文件对象上有一个DateTime
属性。我正在我的客户端应用程序(Xamarin.Forms)中创建一个配置文件对象并将其发布到WebAPI。但是,日期并没有被WebAPI接收。
日期需要以什么格式发送到WebAPI?
修改
简化客户代码:
var formContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("DateOfBirth", date_of_birth.Date.ToUniversalTime().ToString())
});
await Update(formContent);
public async Task<string>Update(FormUrlEncodedContent profileUpdates)
{
var client = new HttpClient();
client.BaseAddress = new Uri(server_url);
var method = new HttpMethod("POST");
var method_url = server_url + "/api/UpdateProfile";
var request = new HttpRequestMessage(method, method_url);
request.Content = profileUpdates;
var response = await client.SendAsync(request);
if (response.StatusCode==HttpStatusCode.OK)
{
return "Profile Updated";
}
}
简化服务器型号
public class Profile
{
public string Name {get;set;}
public DateTime DateOfBirth {get;set;}
}