|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的重定向方法,但似乎不起作用。或者说它没有显示任何东西。任何想法?
| 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.
注意。尽管上面的示例代码您可能需要考虑尝试If-Modified-Since
ZnClient 中的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)