I have a login screen in my app. I want to retrieve the phone number from the input field and send it to my backend server as a post request with volley. The backend server is structured this way:
"user": { "phone": 909099999 } I have tried this block of code:
final String phone = login_phoneTET.getText().toString(); Map<String, String> params = new HashMap<>(); params.put("phone", phone); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Constants.TING_OTP_ENDPOINT, new JSONObject(params), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "Success"); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "Failed with an Error" + error.getMessage()); error.printStackTrace(); } } ) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<>(); headers.put("Content-Type", "application/json; charset=utf-8"); return headers; } }; jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(20000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); VolleySingleton.getVolleySingleton(this).addToRequestQueue(jsonObjectRequest); and also tried using a string request. I keep getting this error in logcat:
E/Volley: [22489] BasicNetwork.performRequest: Unexpected response code 500 for https://:):)/api/user/generateOTP Am I making this request properly or is there a better way to do it? Thanks.