Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:40:06+00:00 2026-06-01T21:40:06+00:00

I used the following C# code from Microsoft to request EWS 2010 MSDN link

  • 0

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 help

    DefaultHttpClient client = new HttpsClient(
                MyActivity.this);

        requestBytes = myXMLStringRequest.getBytes("UTF-8");

        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader("Content-Type", "text/xml;utf-8");
        if (requestBytes != null) {
            httpPost.setHeader("Content-length",
                    String.valueOf(requestBytes.length));
            Log.d(TAG, "content length: " + requestBytes.length);
        }

        client.getCredentialsProvider().setCredentials(
                new AuthScope(url, 443),
                new UsernamePasswordCredentials(userName,
                        password));
        Log.d(TAG, "Begin request");
        HttpResponse response = client.execute(httpPost);
        Log.d(TAG, "status Line: " + response.getStatusLine().toString());

Here is my xml request

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" 
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
<soap:Body>
<GetFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"                xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">   
<FolderShape>     
    <t:BaseShape>Default</t:BaseShape>  
</FolderShape>    
<FolderIds>      
    <t:DistinguishedFolderId Id="inbox"/>     
    <t:DistinguishedFolderId Id="deleteditems"/>  
</FolderIds> 
</GetFolder>

I also use custom HttpsClient with keystore.

public class HttpsClient extends DefaultHttpClient {
private final Context context;

public HttpsClient(final Context context) {
    super();
    this.context = context;
}

/**
 * The method used to create client connection manager
 */
@Override
protected ClientConnectionManager createClientConnectionManager() {
    final SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 8080));

    // Register for port 443 our SSLSocketFactory with our keystore
    // to the ConnectionManager
    registry.register(new Scheme("https", newSslSocketFactory(), 8443));
    return new SingleClientConnManager(getParams(), registry);
}

private SSLSocketFactory newSslSocketFactory() {
    try {
        // Get an instance of the Bouncy Castle KeyStore format
        final KeyStore trusted = KeyStore.getInstance("BKS");
        // Get the raw resource, which contains the keystore with
        // your trusted certificates (root and any intermediate certs)
        final InputStream inputStream = context.getResources().openRawResource(R.raw.parkgroup_ws_client);
        try {
            // Initialize the keystore with the provided truste
            // certificates
            // Also provide the password of the keystore
            trusted.load(inputStream, "myKeyStorePassword".toCharArray());
        } finally {
            inputStream.close();
        }
        // Pass the keystore to the SSLSocketFactory. The factory is
        // responsible
        // for the verification of the server certificate.
        final SSLSocketFactory ssf = new SSLSocketFactory(trusted);
        // Hostname verification from certificate
        // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        return ssf;
    } catch (Exception e) {
        Log.e("MYTAG", e.getMessage());
        throw new AssertionError(e);
    }
}

@Override
protected HttpParams createHttpParams() {
    final HttpParams httpParams = super.createHttpParams();
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
    httpParams.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    return httpParams;
}

}

But it always show “connect timeout” and does not response anything

Please tell me where is my problem? Any example would be help.
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:40:08+00:00Added an answer on June 1, 2026 at 9:40 pm

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the following code to remove script, link tags from my string, $contents='<script>inside
The following code is used to fetch logs from app engine for further processing.
The following code is taken from Project Silk (a Microsoft sample application) The publish
I used following code, but it displays only 2 digit of ISO country name.
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I am trying to used following code but I am not getting good performance
I've used following code snippet for my activity in order to deal with orientation
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
I used following JS code to create equal height columns: var colHeight = Math.max($('.3columngallery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.