How to make a JSON request in a salvo, where I need to send an authentication header and a JSON object in the body, and I expect only 200 status code to respond
JsonObjectRequest request = new JsonObjectRequest( method, url, myJsonObject, responseListener, errorListener) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<String, String>(); String creds = String.format("%s:%s", login, password); String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT); headers.put("Authorization", auth); return headers; } }; new Response.Listener<String>(){ @Override public void onResponse(String response) { Toast.makeText(getActivity(), response, 1000).show(); }
I tried different types of response listeners with a string or JSON object, object, but there is always an error: android volley org.json.JSONException: End of character input 0 from
Or is there any other request in volley that supports both the json object and the authentication header in the body and the response is just an http status code?
source share