RestSharp请求在发送对象时发送DateTime.MinValue

时间:2016-01-30 15:59:45

标签: c# datetime asp.net-web-api restsharp

在正文中或使用RestSharp作为参数发送对象时,DateTime对象属性将被接收为MinValue(对于DateTime可空属性,则为null)。

我的例子:

internal static int RequestWithObjectParam<T>(
    T parameter, string resource, string httpMethod, out string jsonResponseData)
{
    var client = new RestClient(_baseUrl);

    var request = new RestRequest(resource, HttpMethod.VerbStringToHttpVerb(httpMethod));
    request.AddObject(parameter);

    var result = client.Execute(request);

    jsonResponseData = result.Content;

    return (int)result.StatusCode;
}

发送的对象包含一个简单的DateTime属性:

public DateTime LastModification { get; set; }

此字段在发送之前仅设置为DateTime.Now:

lastModification: DateTime.Now,

最后是ActionMethod:

public HttpStatusCode PostParking(Guid key, Parking newParking)

0 个答案:

没有答案