1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(AuthPolicy.NTLM));
httpClient.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory());
httpClient.getCredentialsProvider().setCredentials(new AuthScope(this.host, this.port), new NTCredentials(username, password,workstation,domain));
HttpPost httppost = new HttpPost(this.exchangeEwsUrl);
ContentProducer cp = new ContentProducer() {
@Override
public void writeTo(OutputStream outstream) throws IOException {
Writer writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("" + createItem);
writer.flush();
}
};
HttpEntity entity1 = new EntityTemplate(cp);
Header ctype = new BasicHeader("Content-Type", "text/xml; charset=UTF-8");
Header soapAction = new BasicHeader("SOAPAction", "\"http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder\"");
httppost.setHeaders(new Header[]{ctype, soapAction});
httppost.setEntity(entity1);
HttpContext localContext = new BasicHttpContext();
HttpResponse response1 = httpclient.execute(httppost,localContext);
AuthState proxyAuthState = (AuthState) localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
System.out.println("Proxy auth state: " + proxyAuthState.getAuthScope());
System.out.println("Proxy auth scheme: " + proxyAuthState.getAuthScheme());
System.out.println("Proxy auth credentials: " + proxyAuthState.getCredentials());
AuthState targetAuthState = (AuthState) localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
System.out.println("Target auth state: " + targetAuthState.getAuthScope());
System.out.println("Target auth scheme: " + targetAuthState.getAuthScheme());
System.out.println("Target auth credentials: " + targetAuthState.getCredentials()); |
Partager