您的位置:首页 > 理论基础 > 计算机网络

【Android网络请求】如何使用Volley发送POST请求

2016-07-03 15:59 645 查看

如何使用Volley发送POST请求

try {
RequestQueue mQueue = Volley.newRequestQueue(App.CONTEXT);
JSONObject json = new JSONObject();
json.put("name", "zhangsan");
json.put("pwd", "123456");
JsonObjectRequest stringRequest = new JsonObjectRequest(
Request.Method.POST,                            //POST请求
"http://192.168.2.2:8080/YourProject/loginServlet",     //请求的URL
json,                                           //请求的JSON
(JSONObject response) ->                        //取得返回的JSON数据
Log.d("JsonObjectRequest", response.toString()),
(VolleyError error) ->                          //调用失败的操作
Log.e("TAG", error.getMessage(), error));
mQueue.add(stringRequest);
mQueue.start();
} catch (JSONException e) {
e.printStackTrace();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: