这里安利一个介绍volley几种常用方法的blog:http://blog.csdn.net/fenghai22/article/details/44061307
进入正题,当request header中content-type = application/json时,说明需要post一个json才能获取response。volly提供了一个方法:
public JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) {
super(method, url, jsonRequest == null?null:jsonRequest.toString(), listener, errorListener);
}
同时它的父类JsonRequest也说明了它是针对Json的类
private static final String PROTOCOL_CONTENT_TYPE = String.format("application/json; charset=%s", new Object[]{"utf-8"});
上代码
private void transferByVolley(String url){
RequestQueue requestQueue = Volley.newRequestQueue(mContext);
Map<String, String> params = new HashMap<String, String>();
params.put("key1", value1);
params.put("key2", value2);
params.put("key3",value3);
JSONObject jsonObject = new JSONObject(params);
//注意&