1

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.

2 Answers 2

2

It's a server side error. So i think you need to be concern about your server.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thanks. Could it be int to string or vice versa type conversion error?
May be not. Actually it's quite difficult to answer without seeing code. If you post here related code then it will be easy to try to answer.
0

Please, use https://jsonlint.com/ to validate your json's(the one you send, and the one you get back).

if the JSON you wrote, is the one you are sending:

"user": { "phone": 909099999} 

then its not a valid JSON, and there is your error:

Error: Parse error on line 1: "user": { "phone": 909099 ------^ Expecting 'EOF', '}', ',', ']', got ':' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.