如何每60秒刷新一次会话,并在Pharo的笔录上显示该会话? [英] How can I refresh a session for every 60 second and display it on transcript with Pharo?
本文介绍了如何每60秒刷新一次会话,并在Pharo的笔录上显示该会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
|a b |
a := ZnClient new.
a get: 'http://cloud-storage.com/login'.
a
formAt: 'username' put: 'jom';
formAt: 'password' put: 'mypass';
post;
get: 'http://cloud-storage.com/my-file'.
"Here I want to refresh the session for every 60sec and"
"to checking for newer data"
b := a maxNumberOfRedirects:60
Transcript show: b; cr.
我想实现一种方法,该方法每60秒刷新一次ZnClient会话,以检查我登录的服务器上的较新数据.我尝试了pharo的重定向方法,但似乎不起作用.或说它什么也没显示.有什么主意吗?
I would like to implement a method that can refresh the ZnClient session every 60s for checking for newer data on the server I am logged into. I tried the redirect method of pharo but it does not seem to work. or say It does not show anything. Any idea?
推荐答案
| session data |
session := ZnClient new url: 'http://cloud-storage.com'.
"Login"
session path: '/login';
formAt: 'email' put: 'jom';
formAt: 'password' put: 'mypass';
post.
"Get data"
data := session path: '/my-file'; get; contents.
"Check for new data every 60 secs for maximum 100 tries"
[
100 timesRepeat: [
| newData |
(Delay forSeconds: 60) wait.
newData := session path: '/my-file'; get; contents.
(data ~= newData) ifTrue: [Transcript show: newData; cr]
]
] fork.
NB.尽管有上述示例代码,您可能仍要考虑在ZnClient中尝试If-Modified-Since
方法.
NB. Despite above example code you may want to consider trying If-Modified-Since
method in ZnClient.
这篇关于如何每60秒刷新一次会话,并在Pharo的笔录上显示该会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文