Performing login to https website via Android app

前端 未结 1 1424
情歌与酒
情歌与酒 2020-12-13 12:00

First off, I\'m pretty newb at this. I\'m new to Android, to asp, to javascript, to http even.

I\'m trying to build an Android app that allows me to login to my scho

1条回答
  •  再見小時候
    2020-12-13 12:25

    Below code handles https and gives httpsclient for https url .. you need httpsclient to make request to https urls.

    Might below code is of help to you:

    public DefaultHttpClient getClient() 
       {
            DefaultHttpClient ret = null;
    
            //sets up parameters
            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, "utf-8");
            params.setBooleanParameter("http.protocol.expect-continue", false);
    
            //registers schemes for both http and https
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
            sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
            registry.register(new Scheme("https", sslSocketFactory, 443));
    
            ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
            ret = new DefaultHttpClient(manager, params);
            return ret;
        }
    

    0 讨论(0)
提交回复
热议问题