Flex 向 time.nist.gov 发送移动请求
如何从 Flex 移动应用程序中访问 time.nist.gov 等互联网时间服务提供的时间?
有没有办法通过 URLRequest 或 HTTPService 来做到这一点?
好的,这里是使用简单的 HTTPService 来调用 Yahoo WebServices;
<s:HTTPService id="serverTime" url="http://developer.yahooapis.com/TimeService/V1/getTime?appid=myID" result="resultHandler(event)" resultFormat="e4x"/>
在我的 resultHandler 中,时间戳上的跟踪已经失败(不返回任何值);
private function resultHandler(event:ResultEvent):void {
// this works (outputs the xml as shown on Yahoo
trace(event.result);
var xmlResult:XML = event.result as XML;
var timestamp:String = xmlResult.Timestamp;
trace("stamp" + timestamp);
}
How do I access the time provided by internet time services like time.nist.gov from within my Flex mobile application?
Is there a way to do this via URLRequest or HTTPService?
Alright, here is the call to the Yahoo WebServices with a simple HTTPService;
<s:HTTPService id="serverTime" url="http://developer.yahooapis.com/TimeService/V1/getTime?appid=myID" result="resultHandler(event)" resultFormat="e4x"/>
In my resultHandler, the trace on Timestamp already fails (returns no value);
private function resultHandler(event:ResultEvent):void {
// this works (outputs the xml as shown on Yahoo
trace(event.result);
var xmlResult:XML = event.result as XML;
var timestamp:String = xmlResult.Timestamp;
trace("stamp" + timestamp);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
time.nist.gov(或任何其他时间服务器)使用 NTP 协议进行通信,而不是 HTTP,因此您不能使用 URLRequest 或 HTTPService。
我不知道 ActionScript 中有任何 NTP 客户端实现。您可能需要自己做。
根据您的需要,您可以使用提供“相当准确”时间的网络服务,例如 雅虎网络服务。这通过 HTTP 进行,因此您可以在 Flex 中使用 URLRequest 或 HTTPService。
time.nist.gov (or any other time server) use NTP protocol for communication, not HTTP, so you can't use URLRequest or HTTPService.
I don't know of any NTP client implementation in ActionScript. You may need to do your own.
Depending on your needs, you may use a webservice that provides "pretty accurate" time, like Yahoo WebServices. This goes over HTTP, so you can use URLRequest or HTTPService in Flex.