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 {
        SSLSocketFactorysslSocketFactory= SSLSocketFactory
                .getSocketFactory();
        if (keyStore != null && trustStore != null) {
            sslSocketFactory = newSSLSocketFactory(keyStore,
                    KEYSTORE_PASSWORD, trustStore);
        } elseif (trustStore != null) {
            sslSocketFactory = newSSLSocketFactory(trustStore);
        }

        return createHttpClient(sslSocketFactory);
    } catch (GeneralSecurityException e) {
        thrownewRuntimeException(e);
    }
}

Then I add CredentialsProvider for authentication.

DefaultHttpClientclient= createHttpClientWithDefaultSocketFactory(
                keyStore, trustStore);
        HttpPosthttpPost=newHttpPost(SERVER_AUTH_URL);
        httpPost.setHeader("Content-type", "text/xml;utf-8");

        StringEntityse=newStringEntity(builder.toString(), "UTF8");
        se.setContentType("text/xml");
        httpPost.setEntity(se);
        CredentialsProvidercredProvider=newBasicCredentialsProvider();

        credProvider.setCredentials(newAuthScope(URL,
                443), newUsernamePasswordCredentials(USERNAME, password));

        // This will exclude the NTLM authentication scheme

        client.setCredentialsProvider(credProvider);
        HttpResponseresponse= 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"