简体   繁体   English

如何请求安全连接(https)?

[英]How to request a secured connection (https)?

Generally, we use http connection like this: 通常,我们使用http连接,如下所示:

try{

            HttpClient httpclient = new DefaultHttpClient();
//              final HttpParams params = httpclient.getParams();
//              HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
//              HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT);
//              ConnManagerParams.setTimeout(params, WAIT_TIMEOUT);

                HttpPost httppost = new HttpPost(url);
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();

        }catch(Exception e){
              // Log.e("log_tag", "Error in http connection "+e.toString());
        }

This code snippet is used for http. 此代码段用于http。

How can I request a secured connection (https) ? 如何请求安全连接(https)?

If you are after Android 2.2, you can simply use class AndroidHttpClient . 如果您使用的是Android 2.2,则可以只使用类AndroidHttpClient
It will be work through https, if url scheme is https. 如果url方案为https,它将通过https工作。

Otherwise, you can look to its source and make similar, and may be even easier. 否则,您可以查找其来源并进行相似处理,甚至可能会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM