简体   繁体   English

将Datetime作为querystring参数传递给Servicestack.net GET方法时出错

[英]Error passing Datetime as querystring parameter to Servicestack.net GET method

I trying to pass a DateTime object as a query string parameter to a webservice method built with ServiceStack.net. 我试图将DateTime对象作为查询字符串参数传递给使用ServiceStack.net构建的Webservice方法。

The date is properly URL encoded when passed but I keep getting the following error: 通过日期时,URL已正确编码,但我不断收到以下错误:

"Message":"KeyValueDataContractDeserializer: Error converting to type: String was not recognized as a valid DateTime.

Any ideas of how to correct this? 关于如何纠正这一点的任何想法?

Here is an example of the URL encoded DateTime I was passing: 2%2f24%2f2012+5%3a13%3a02+PM 这是我正在传递的URL编码的DateTime的示例:2%2f24%2f2012 + 5%3a13%3a02 + PM

If you have to pass datetimes as strings, try to pass them in an unambiguous format. 如果必须将日期时间作为字符串传递,请尝试以明确的格式传递它们。 I assume you're tying to pass the 24th February 2012, 17:13:02 - something like the following would be unambiguous: 我假设您打算通过2012年2月24日17:13:02-类似以下内容将是明确的:

2012-02-24T17:13:02

Eg if you're formatting the date in .NET, use "o" or "s" 例如,如果您要在.NET中格式化日期,请使用“ o”或“ s”


This is nothing to do with URL encoding - it's to do with passing data unambiguously - dates such as 01/02/2012 can be interpreted at least two ways - 1st February or 2nd January of this year, for two. 这与URL编码无关 -与明确地传递数据有关-诸如2012年1月2日这样的日期至少可以用两种方式解释-今年2月1日或1月2日,有两种方式。

您是否考虑过让websservice接受字符串参数,然后使用DateTime.Parse或DateTime.TryParse将字符串转换为DateTime?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM