Yes you can. The JSON is added to the body of a POST request, like this:
JSONObject jsonObject; // your JSON here
requestQueue.add(new JsonObjectRequest(Method.POST, url, jsonObject, listener, errorListener);
Domanda
Can we post JsonObject or JsonArray using Android volley to the server?If yes can anyone please send the working sample. If i post string then it works fine but i have some problem while posting jsonObject or jsonArray.
Soluzione
Yes you can. The JSON is added to the body of a POST request, like this:
JSONObject jsonObject; // your JSON here
requestQueue.add(new JsonObjectRequest(Method.POST, url, jsonObject, listener, errorListener);
Altri suggerimenti
Yes, just add data to JSONObject and pass that object in the request.
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("password", password);
RequestQueue queue = Volley.newRequestQueue(context);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, URL, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("volley", "response: " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("volley", "error: " + error);
}
});