用HTTPClient访问exchange服务器报错,大家帮忙看下!
具体错误信息:
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;