O
O
Olzhas Ilyubayev2014-05-19 22:49:47
Java
Olzhas Ilyubayev, 2014-05-19 22:49:47

How to log into a website via HTTPS in Android?

There is a goal - to write an Android application that will log in to the site (correspondingly, we have a page with a login form) and then receive private information available after authorization.
In this case, we have the HTTPS protocol.
What methods do you suggest? Libraries?
It would be great to see examples or any open source projects.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Olzhas Ilyubayev, 2015-01-26
@ilyubayev

A lot of water has flowed under the bridge since the question.
It is worth using HTTPUrlConnection for http requests in android - it is recommended by Google. HTTPClient is an obsolete library.
This article helped a lot: www.mkyong.com/java/how-to-automate-login-a-websit...
From the libraries I used: jsoup.com

A
Andrew, 2014-05-20
@3mph4515

Hmm, what is your actual snag? You do not HHTPClient, but HTTPS with a certificate. You can work with it
Here is an example from my project:

private static DefaultHttpClient getThreadSafeClientHTTPS(Context context)
      throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException,
      KeyStoreException, java.security.cert.CertificateException, FileNotFoundException {
    KeyStore trustStore = KeyStore.getInstance("BKS");
    AssetManager assetManager = context.getAssets();
    InputStream instream = null;
    try {
      instream = assetManager.open("PATH TO CERT");
    } catch (IOException e1) {
      e1.printStackTrace();
    }
    try {
      // password 
      trustStore.load(instream, PASSWORD HERE);
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        instream.close();
      } catch (Exception ignore) {
      }
    }

    // Create socket factory with given keystore.
    SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
    socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme sch = new Scheme("https", socketFactory, 443);

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    DefaultHttpClient client = new DefaultHttpClient(params);
    ClientConnectionManager mgr = client.getConnectionManager();
    params = client.getParams();

    int timeoutConnection = 10 * 1000;
    HttpConnectionParams.setConnectionTimeout(params, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = 20 * 1000;
    HttpConnectionParams.setSoTimeout(params, timeoutSocket);
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()),
        params);
    client.getConnectionManager().getSchemeRegistry().register(sch);
    return client;
  }

D
Dreddik, 2014-05-20
@Dreddik

URLConnection will help you establish a connection and receive data
. The rest is a matter of technology.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question