用HTTPClient访问exchange服务器报错,大家帮忙看下!

时光瞄 2011-04-13 02:38:28
具体错误信息:
401 - 未授权: 由于凭据无效,访问被拒绝。
您无权使用所提供的凭据查看此目录或页面。
访问代码:

Protocol myHTTPS = new Protocol("https",
new MySecureProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", myHTTPS);
// 设置连接参数
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, "gbk");
PostMethod postMethod = new PostMethod(mailServer
+ "/owa/auth/owaauth.dll");
postMethod.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
NameValuePair destination = new NameValuePair("destination",
mailServer + "/owa/");
NameValuePair flag = new NameValuePair("flag", "0");
NameValuePair forcedownlevel = new NameValuePair("forcedownlevel",
"0");
NameValuePair trusted = new NameValuePair("trusted", "0");
NameValuePair username = new NameValuePair("username", user);
NameValuePair password = new NameValuePair("password", pw);
NameValuePair[] FieldArr = new NameValuePair[] { destination, flag,
forcedownlevel, trusted, username, password };
postMethod.addParameters(FieldArr);
// 取邮件数
int statusCode = httpClient.executeMethod(postMethod);
GetMethod redirect = new GetMethod(mailServer + "/owa/");
redirect.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, "gbk");
httpClient.executeMethod(redirect);
String str = redirect.getResponseBodyAsString();
System.out.println(str);
logger.debug(str);
int start = str.indexOf("</a><span class=\"unrd\">");
int end = str.indexOf(")</span></td></tr><tr>");
if (start != -1 && end != -1) {
start += "</a><span class=\"unrd\">".length();
rtnStr = str.substring(start + 1, end);
}
postMethod.releaseConnection();
httpClient = null;

返回值就是上面说的服务器错误信息。
但是我通过网页登陆是正常的,请问大家这是怎么回事!
...全文
321 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ncowboy 2011-06-03
  • 打赏
  • 举报
回复
你想用程序操作用户的邮箱?如果条件可以,尝试使用ews(exchange web services)吧。
登录owa很麻烦。

如果你真要走owa,用fiddler抓下包,看看到底传了什么数据过去。重要的是,你看看传过去的ID和密码是否被转换了。
arong1234 2011-04-13
  • 打赏
  • 举报
回复
不是说你有user/password http client就自动会帮你验证的
你需要用诸如FBA之类的机制进行验证
不过我没有例子了,你自己检索一下FBA, Form based authentication

时光瞄 2011-04-13
  • 打赏
  • 举报
回复

没人帮忙看下吗

535

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 Exchange Server
社区管理员
  • 消息协作社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧