Exchange 2007及后续版本提供了EWS,等于是提供了一个供其他应用使用的接口,而我们的Exchange是2003版,没有EWS,貌似不能方便地把其他系统的Calendar同步到Exchange...
有人说,用WebDAV可以,但我觉得还是复杂了点。
昨天看到HTTPBuilder,刹那间有了办法:我们不是有Exchange提供的webmail吗?我们可以手动登录上去操作自己的Calendar,可不可以让几行代码替我们去做这个事情呢?很到应用所做的事情不过是代替人工操作而已。
开始研究:
打开浏览器,指向Microsoft Outlook Web Access,出现登录页面
View Source,Ctrl + F,找'<form'和'<INPUT',不难找到登录表单提交的url和传输的表单变量:
<FORM action="/exchweb/bin/auth/owaauth.dll" method="POST" name="logonForm">
<INPUT type="hidden" name="destination" value="https://webmail.domain.com/Exchange/">
<INPUT type="hidden" name="flags" value="0">
<INPUT type="text" id="username" name="username"...
<INPUT type="password" autocomplete="off" style="width:100%" id="password" name="password"...
在groovyConsole中写几行代码并执行以下看看:
import groovyx.net.http.* def http = new HTTPBuilder( 'https://webmail.domain.com' ) http.post( path: '/exchweb/bin/auth/owaauth.dll', body: [destination:'https://webmail.domain.com/Exchange', flags:'0', username:'domain/username', password:'pwd']) {res-> if( res.statusLine.statusCode == 302 ) { println 'logged in successfully.' } } http.get( path: '/Exchange/username/日历', contentType:groovyx.net.http.ContentType.TEXT, query:[Cmd:'contents']) {res, reader-> System.out << reader }
成功地读取了我的日历!按照这种先登录后操作的模式来,操作Exchange Server上的Calendar乃至Task,Inbox等其他Folders也是举手之劳而已。