0

String request return null output in android studio when i used jsonobject request it will give correct output.

RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);

    Log.d(TAG, " url=" + URL);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d(TAG, " response=" + response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, " error=" + error);

        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            LinkedHashMap<String, String> linkmap = new LinkedHashMap<>();
            linkmap.put("p_ENTITY_ID", "2");
            linkmap.put("p_ORGCD", "p01");
            linkmap.put("p_COMPCD", "A0002");
            linkmap.put("p_DIVCD", "");
            linkmap.put("p_USERID", "");
            linkmap.put("p_ACDYR", "");
            linkmap.put("p_TYPE", "ACDYR_DDL");
            linkmap.put("p_FILTER1", "");
            linkmap.put("p_FILTER2", "");
            linkmap.put("p_DEFUNCT", "");

            Log.d(TAG, " MAP=" + linkmap);
            return linkmap;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            LinkedHashMap<String, String> headers = new LinkedHashMap<>();
            return headers;
        }


    };

     requestQueue.add(stringRequest);

}
  • used this two methods instead of getparams and getheaders Override public String getBodyContentType() { return "application/json; charset=utf-8"; } @Override public byte[] getBody() throws AuthFailureError { try { return requestBody == null ? null : requestBody.getBytes("utf-8"); } catch (UnsupportedEncodingException uee) { VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8"); return null; } } – amol ingawale Feb 03 '18 at 12:02
  • https://stackoverflow.com/questions/33573803/how-to-send-a-post-request-using-volley-with-string-body – amol ingawale Feb 03 '18 at 12:12

0 Answers0