Q:

posting data to server in json format using volley

Hello i am posting data to server in json format,
but it returns volley server error in error response`
RequestQueue queue = Volley.newRequestQueue(this);
        JSONObject jobj=new JSONObject();
        try {
            jobj.put("id",”123”);
            jobj.put("session","new");
            JSONArray array = null;
            array = new JSONArray();
            for (int i = 0;i<3;i++){
               JSONObject jsonObject = new JSONObject();
                jsonObject.put("name","test");
                jsonObject.put("content","test");
                jsonObject.put("time"," 2016-04-07T11:44:22.407Z ");
                array.put(jsonObject);
            }
            Log.e(" array "," arrr"+array.toString());
            jobj.put("data",array);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.e("jsondata",jobj.toString());
JsonObjectRequest sr=  new JsonObjectRequest(post_url, jobj, new Response. Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                            }

        }, new Response. ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }){
            @OveRequestQueue queue = Volley.newRequestQueue(this);
        JSONObject jobj=new JSONObject();
        try {
            jobj.put("id",”123”);
            jobj.put("session","new");
            JSONArray array = null;
            array = new JSONArray();
            for (int i = 0;i<3;i++){
               JSONObject jsonObject = new JSONObject();
                jsonObject.put("name","test");
                jsonObject.put("content","test");
                jsonObject.put("time"," 2016-04-07T11:44:22.407Z ");
                array.put(jsonObject);
            }
            Log.e(" array "," arrr"+array.toString());
            jobj.put("data",array);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.e("jsondata",jobj.toString());
JsonObjectRequest sr=  new JsonObjectRequest(post_url, jobj, new Response. Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                            }

        }, new Response. ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {

            }rride
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String,String> params = new HashMap<String, String>();
                params.put("Content-Type","application/json");
                return params;
            }
        };
        queue.add(sr);`

A:

Have a singleton which handles the request queue. 
public class VolleySingleton {

    // Singleton object...
    private static VolleySingleton instance;

    final private RequestQueue requestQueue;
    private static ImageLoader imageLoader;

    //Constructor...
    private VolleySingleton(Context context) {

        requestQueue = Volley.newRequestQueue(context);

        imageLoader = new ImageLoader(requestQueue, new ImageLoader. ImageCache() {
            private final LruCache<String, Bitmap> cache = new LruCache<>(100000000);

            @Override
            public Bitmap getBitmap(String url) {
                return cache.get(url);
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
                cache.put(url, bitmap);
            }
        });
    }

    // Singleton method...
    public static VolleySingleton getInstance(Context context) {
        if (instance == null) {
            instance = new VolleySingleton(context);
        }
        return instance;
    }

    public RequestQueue getRequestQueue(Context context) {
        if (requestQueue ! = null) {
        return requestQueue;
        } else {
            getInstance(context);
            return requestQueue;
        }
    }

    private  RequestQueue getRequestQueue() {
        return requestQueue;
    }

    public static ImageLoader getImageLoader(Context context) {
        if (imageLoader ! = null) {
            return imageLoader;
        } else {
            getInstance(context);
            return imageLoader;
        }
    }

    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag("App");
        getRequestQueue().add(req);
    }

}

Then using the below method you can send the request. 
public void postVolley(final Context context, String url, JSONObject jsonObject) {

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request. Method. POST, url, jsonObject, new Response. Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject responseJson) {
                Log.e("success", "" + responseJson.toString());
            }

        }, new Response. ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("error", "" + error);

            }
        }) {

            /**
             * Setting the content type
             */

            @Override
            public String getBodyContentType() {
                return "application/json;charset=UTF-8";
            }
        };

        VolleySingleton.getInstance(context).addToRequestQueue(jsonObjReq);

    }

This works fine for me.