博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android带参数链接请求服务器
阅读量:6885 次
发布时间:2019-06-27

本文共 1517 字,大约阅读时间需要 5 分钟。

public void taste() {

//设默认值
SharedPreferences.Editor editor = this.getSharedPreferences("setting", 0).edit();
editor.putString("isTaste", "1");
editor.putString("customerId", "1219");
editor.putString("userAccount", "admin");
editor.putString("password", "123456");
editor.putString("accountType", "1");
editor.commit();
//要访问的服务地址
String url = "http://www.gpsonline.cn/mobile/CheckAccount.aspx";
//POST方式
HttpPost request = new HttpPost(url);
//post参数值
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("customerId", "1219"));
params.add(new BasicNameValuePair("userAccount", "admin"));
params.add(new BasicNameValuePair("password", "123456"));
params.add(new BasicNameValuePair("accountType", "1"));
try {
//添加post参数值
HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
request.setEntity(entity);
//开始访问
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
//响应为成功
if (response.getStatusLine().getStatusCode() == 200) {
clear();
//获得返回内容
String result = EntityUtils.toString(response.getEntity());
//将返回值转为JSON
JSONObject json = new JSONObject(result);
JSONArray groups = json.optJSONArray("groups");
createGroupAndVehicle(groups, "0");
//打开Activity并把JSON值传过去
Intent intent = new Intent();
intent.setClass(LoginTabActivity.this, GPSMapActivity.class);
intent.putExtra("groupId", "0");
startActivity(intent);
}
} catch (Exception e) {
Log.e("e", e.getMessage());
}
}

转载于:https://www.cnblogs.com/leischen/p/3169395.html

你可能感兴趣的文章
python 位操作符 左移和右移 运算
查看>>
预备作业①
查看>>
跨域 - jsonp轻松搞定跨域请求
查看>>
css布局 - 工作中常见的两栏布局案例及分析
查看>>
个人代码库のC#背景色渐变的功能
查看>>
基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境
查看>>
承接上面一遍的(后续步骤)
查看>>
杂笔感想
查看>>
Source Insight 常用设置
查看>>
android anr什么意思?
查看>>
视频: DroidPilot - 增强多应用集成测试 - V2.1.0 (新)
查看>>
python实现逐行替换超大文件中的字符串
查看>>
软件工程例子
查看>>
python全栈开发,Day43(引子,协程介绍,Greenlet模块,Gevent模块,Gevent之同步与异步)...
查看>>
异步编程与多线程编程的联系和区别
查看>>
单例模式(Singleton Pattern)
查看>>
SQL Server
查看>>
pre标签内文本自动换行
查看>>
RCF的简单使用教程以及什么是回调函数
查看>>
java的Pattern类
查看>>