【发布时间】:2018-05-19 17:28:57
【问题描述】:
您好,我有 C# (Xamarin) 应用程序和 .net API。如何将 DateTime 发布到我的 .Net API?
.Net API
目前我有:
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Email", u.Email),
new KeyValuePair<string, string>("Password", u.Password),
new KeyValuePair<string, string>("ConfirmPassword", u.ConfirmPassword),
new KeyValuePair<string, string>("Gender", u.Gender),
new KeyValuePair<string, string>("DateOfBirth", u.DateOfBirth)
});
HttpResponseMessage response = await client.PostAsync("/api/Account/Register", formContent);
所有字符串都可以正常工作,但是我无法弄清楚 DateTime 字符串。我猜它是:
KeyValuePair<string, DateTime>("DateOfBirth", u.DateOfBirth)
但这不起作用。如果我将 DateTime 转换为字符串,则服务器上的日期只是 01/01/1900,这也不正确。
【问题讨论】:
标签: c# datetime asp.net-web-api dotnet-httpclient