volley的get请求与post请求简单标准代码
可以方便以后使用
---GET---
// String baseUrl = "http://abc.com"; // // HashMap<String, Object> params = new HashMap<>(); // params.put("name", "abc"); // params.put("age", "123"); // String url = UrlUtil.appendUrl(baseUrl, params); // // RequestQueue queue = Volley.newRequestQueue(ctx); // // StringRequest request = new StringRequest(com.android.volley.Request.Method.GET, url, new com.android.volley.Response.Listener<String>() { // @Override // public void onResponse(String response) { // String result = response; // } // }, new com.android.volley.Response.ErrorListener() { // @Override // public void onErrorResponse(VolleyError error) { // // } // }); // // queue.add(request);
---POST---
// String url = "http://abc.com"; // RequestQueue queue = Volley.newRequestQueue(ctx); // // StringRequest request = new StringRequest(com.android.volley.Request.Method.POST, url, new com.android.volley.Response.Listener<String>() { // @Override // public void onResponse(String response) { // String result = response; // } // }, new com.android.volley.Response.ErrorListener() { // @Override // public void onErrorResponse(VolleyError error) { // // } // }) { // @Override // protected Map<String, String> getParams() throws AuthFailureError { // HashMap<String, String> params = new HashMap<>(); // params.put("name", "abc"); // params.put("age", "123"); // return params; // } // }; // // queue.add(request);