lundi 23 mai 2016

how to read response body data in volley ...?

im sending user login request with raw data using volley ..? when login sucess then responce return 200 status . and array list in body .

with this code im only getting the 200 status code im not able to get the body data. private void LoginUser() { // showProgressDialog(); JSONObject jsonObject = new JSONObject(); try {jsonObject.put("passwordHash","sfdfdfdsf");jsonObject.put("username","myusername");} catch (JSONException e){e.printStackTrace();} jsonStr =jsonObject.toString(); //json string variable Hold the {"username":"eg@gmail.com","passwordHash":"dfdffd"} RequestQueue requestQueue = Volley.newRequestQueue(this); StringRequest stringRequest = new StringRequest(Request.Method.POST, SignInUrl, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d("TAG", response); Toast.makeText(getBaseContext(),response, Toast.LENGTH_LONG).show(); hideProgressDialog(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("VOLLEY", error.toString()); Toast.makeText(getBaseContext(),error.toString(), Toast.LENGTH_LONG).show(); } }){ @Override public String getBodyContentType() { return "application/json; charset=utf-8"; } @Override public byte[] getBody() { try { return jsonStr == null ? null : jsonStr.getBytes("utf-8"); } catch (UnsupportedEncodingException uee) { VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", jsonStr, "utf-8"); return null; } } @Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String responseString = ""; if (response != null) { responseString = String.valueOf(response.statusCode); } return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response)); } @Override public Map<String,String> getHeaders() throws AuthFailureError { Map<String,String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json; charset=utf-8"); return headers; }}; requestQueue.add(stringRequest); }

enter code here




Aucun commentaire:

Enregistrer un commentaire