如何使用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();
}