Android的发展:如何通过HTTPS创建网络登录 [英] Android Development: How to create a network login via https
本文介绍了Android的发展:如何通过HTTPS创建网络登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网上搜索,并没有用我已找到了答案,我的问题。
我需要我的Android应用程序连接到我的网络服务器。
例如 https://开头服务器的地址:PORT /
我怎样才能做到这一点?
解决方案
{尝试
字符串URL =https://开头服务器的地址:PORT /网站/登录用户名=+用户+&放大器;密码=+密码;
的HttpParams PARAMS =新BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(参数,可以1000 * 60 * 2);
HttpConnectionParams.setSoTimeout(PARAMS,0);
HttpClient的HttpClient的=新DefaultHttpClient(PARAMS); // prepare的HTTP GET调用
HTTPGET HTTPGET =新HTTPGET(URL);
//得到响应实体
HttpEntity实体= httpClient.execute(HTTPGET).getEntity(); 如果(实体!= NULL){
//获取响应内容作为一个字符串
字符串的响应= EntityUtils.toString(实体);
//消耗实体
entity.consumeContent(); //当不再需要HttpClient的实例,关闭连接管理器,以确保所有的系统资源释放立即
。httpClient.getConnectionManager()关机();
}
}赶上(例外五){
e.printStackTrace();
}
I have searched the web and to no avail have I found the answer to my problem.
I require my android app to connect to my web server.
example https://SERVER-ADDRESS:PORT/
How can I do this?
解决方案
try{
String url = "https://SERVER-ADDRESS:PORT/site/login?username=" + user + "&password=" + password;
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 1000 * 60 * 2);
HttpConnectionParams.setSoTimeout(params, 0);
HttpClient httpClient = new DefaultHttpClient(params);
//prepare the HTTP GET call
HttpGet httpget = new HttpGet(url);
//get the response entity
HttpEntity entity = httpClient.execute(httpget).getEntity();
if (entity != null) {
//get the response content as a string
String response = EntityUtils.toString(entity);
//consume the entity
entity.consumeContent();
// When HttpClient instance is no longer needed, shut down the connection manager to ensure immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
}
}catch (Exception e) {
e.printStackTrace();
}
这篇关于Android的发展:如何通过HTTPS创建网络登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文