Volley的Post用法

来源:互联网 发布:好的兼职软件 编辑:程序博客网 时间:2024/05/24 00:47

volley的好处这里就不介绍了,这些资料很多,这里只记录volley的最简单直接的用法:

private RequestQueue mQueue;mQueue = Volley.newRequestQueue(this);// 网络请求队列创建//这里创建一个HashMap,用来存放参数,发给服务器Map<String, String> params = new HashMap<String, String>();        params.put("latitude", latitude+"");// 经度        params.put("longitude", longitude+"");// 纬度        params.put("username", "liuxd");// 用户名        params.put("weiz", tv.getText().toString());// 地址        params.put("imei", id);// 设备号        params.put("type", "1");// 类型:1//这里对服务器进行请求        JsonObjectRequest newMissRequest = new JsonObjectRequest(                Request.Method.POST, url, new JSONObject(params),                new Response.Listener<JSONObject>() {                    // 请求成功                    @Override                    public void onResponse(JSONObject jsonobj) {                                Toast.makeText(getApplicationContext(), "签到成功", 0).show();                            }                        }                    }                }, new Response.ErrorListener() {                    // 请求失败                    @Override                    public void onErrorResponse(VolleyError error) {                        Toast.makeText(getApplicationContext(), "签到失败,请检查网络", 0).show();                    }                });        // 加入队列        mQueue.add(newMissRequest);        // 开始        mQueue.start();    }


本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1730057

原创粉丝点击