zoukankan      html  css  js  c++  java
  • Android带参数链接请求服务器

    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());
    }
    }

  • 相关阅读:
    8.7题解
    2019.9.16 csp-s模拟测试44 反思总结
    洛谷P3168 [CQOI2015]任务查询系统
    洛谷P2468 [SDOI2010]粟粟的书架
    2019.8.14 NOIP模拟测试21 反思总结
    2019.8.13 NOIP模拟测试19 反思总结
    2019.8.12 NOIP模拟测试18 反思总结
    大约是个告别【草率极了】
    2019.8.10 NOIP模拟测试16 反思总结【基本更新完毕忽视咕咕咕】
    2019.8.9 NOIP模拟测试15 反思总结
  • 原文地址:https://www.cnblogs.com/leischen/p/3169395.html
Copyright © 2011-2022 走看看