C# 使用Refit序列化并用作url参数时,DateTime会丢失精度
我正在构建一个API网关,它有一个以DateTime值为参数的端点。它使用Refit将此查询转发给底层微服务 我的问题是,当构建微服务查询的URL时,DateTime值已经失去了精度 在构建URL时,是否有方法将Refit配置为使用自定义日期时间序列化程序 microservice端点的定义如下:C# 使用Refit序列化并用作url参数时,DateTime会丢失精度,c#,asp.net-core,refit,C#,Asp.net Core,Refit,我正在构建一个API网关,它有一个以DateTime值为参数的端点。它使用Refit将此查询转发给底层微服务 我的问题是,当构建微服务查询的URL时,DateTime值已经失去了精度 在构建URL时,是否有方法将Refit配置为使用自定义日期时间序列化程序 microservice端点的定义如下: [Get("/client-sales")] Task<ClientSaleCollectionR12n> SearchClientSales([Header("Authorization
[Get("/client-sales")]
Task<ClientSaleCollectionR12n> SearchClientSales([Header("Authorization")] string authorization,
DateTime? completedAfter = null,
DateTime? completedBefore = null);
转发到基础微服务时变为:
GET /client-sales?completedAfter=03%2F20%2F2020%2014%3A54%3A26&completedBefore=03%2F21%2F2020%2015%3A16%3A33
我能够在定义接口时指定格式
Task<ClientSaleCollectionR12n> SearchClientSales([Header("Authorization")] string authorization,
[Query(Format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")] DateTime? completedAfter = null,
[Query(Format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")] DateTime? completedBefore = null);
任务SearchClientSales([标题(“授权”)]字符串授权,
[查询(Format=“yyyy'-'MM'-'dd'T'HH':'MM':'ss.'fff'Z')]DateTime?completedAfter=null,
[查询(Format=“yyyy'-'MM'-'dd'T'HH':'MM':'ss.'fff'Z')]DateTime?completedBefore=null);
:QueryAttribute现在有一个Format属性,可用于FormUrlEncoded值和url编码值。是的,将refit更新到最新版本后,我可以使用[Query(Format=“yyy-MM-ddThh:HH:ss.fff”)]
Task<ClientSaleCollectionR12n> SearchClientSales([Header("Authorization")] string authorization,
[Query(Format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")] DateTime? completedAfter = null,
[Query(Format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'")] DateTime? completedBefore = null);