Skip to content Skip to sidebar Skip to footer

Request Exchange Web Services 2007/2010 With SOAP+XML Over HTTPS In Android

I used the following C# code from Microsoft to request EWS 2010 MSDN link and it worked. I need the same solution for android. I tried to use the following code but it does not he

Solution 1:

Many thanks to Nikolay Elenkov!

Finally, I found the solution. I follow this link: Using a Custom Certificate Trust Store on Android

First, I use DefaultHttpClient instead of HttpClient (the method createHttpClientWithDefaultSocketFactory() should be return DefaultHttpClient):

private DefaultHttpClient createHttpClientWithDefaultSocketFactory(
        KeyStore keyStore, KeyStore trustStore) {
    try {
        SSLSocketFactory sslSocketFactory = SSLSocketFactory
                .getSocketFactory();
        if (keyStore != null && trustStore != null) {
            sslSocketFactory = new SSLSocketFactory(keyStore,
                    KEYSTORE_PASSWORD, trustStore);
        } else if (trustStore != null) {
            sslSocketFactory = new SSLSocketFactory(trustStore);
        }

        return createHttpClient(sslSocketFactory);
    } catch (GeneralSecurityException e) {
        throw new RuntimeException(e);
    }
}

Then I add CredentialsProvider for authentication.

    DefaultHttpClient client = createHttpClientWithDefaultSocketFactory(
                keyStore, trustStore);
        HttpPost httpPost = new HttpPost(SERVER_AUTH_URL);
        httpPost.setHeader("Content-type", "text/xml;utf-8");

        StringEntity se = new StringEntity(builder.toString(), "UTF8");
        se.setContentType("text/xml");
        httpPost.setEntity(se);
        CredentialsProvider credProvider = new BasicCredentialsProvider();

        credProvider.setCredentials(new AuthScope(URL,
                443), new UsernamePasswordCredentials(USERNAME, password));

        // This will exclude the NTLM authentication scheme

        client.setCredentialsProvider(credProvider);
        HttpResponse response = client.execute(httpPost);

Now, it can work well!


Post a Comment for "Request Exchange Web Services 2007/2010 With SOAP+XML Over HTTPS In Android"