将日期时间从 Android 发布到 WCF RESTful JSON 服务

2024-04-02

我正在尝试发送DateTime作为通过使用 JSON 编码的 WCF RESTful 服务公开的方法的参数。该请求如下所示:

POST http://IP:PORT/LogService/json/GetLogEntriesByModule HTTP/1.1
Content-Length: 100
Content-Type: application/json
Host: IP:PORT
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue

{"maxentries":10,"upperdate":"1280703601462","lowerdate":"1277938801462","module":"Windows Service"}

我尝试了几种格式DateTime:

  • 2010-07-01T10:54:00(这是由WCFTestClient通过 NET.TCP 的应用程序并得到结果
  • \/Date(12345678+0100)\/
  • 01.07.2010 10:54:00

方法定义:

LogEntry[] GetLogEntriesByModule(
    string module,
    DateTime lowerDate,
    DateTime upperDate,
    int maxEntries,
    out bool maxEntriesReached
)

我总是得到以下回复:

HTTP/1.1 200 OK
Content-Length: 60
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 02 Jul 2010 09:07:04 GMT

{"GetLogEntriesByModuleResult":[],"maxEntriesReached":false}

看来DateTime未正确解析,因为当时的 Llog 中有多个条目。

有谁知道如何做到这一点?

Update: 问题出在服务器端,已经解决。


将日期发布到 WCF 服务的正确格式是使用:/Date(53244000000)/其中括号中的数字是自 1970 年 UTC 午夜以来的毫秒数。

Date dt = new Date();
long date = Date.UTC(dt.getYear(), dt.getMonth(), dt.getDay(), dt.getHours(),dt.getMinutes(), dt.getSeconds());
String senddate = "/date("+date+")/";

然后按如下方式使用它

inputparam.put("DateTime", datetime);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将日期时间从 Android 发布到 WCF RESTful JSON 服务 的相关文章

随机推荐