Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volley post method return response code 500

Always i get below error response when using volley

06-24 15:06:59.244: E/Volley(12869): [2311] BasicNetwork.performRequest: Unexpected response code 500 for http://My_API

my code for Volley call

String sSignupUrl = STController.getInstance()
                .getResourceManager(LoginActivity.this)
                .getServerPropertyValue(URLConstants.API_LOGIN);
JSONObject params = new JSONObject();
        try {
            params.put("username", "usernam");
            params.put("passwd", "password");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
                sSignupUrl, params, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        LogUtil.d("TAG" + response.toString());
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d("TAG", "Error: " + error.getMessage());
                    }
                }) {

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }

        };

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonObjReq);

I can successfully get the response when using URLConnection manager, not able to find the error, i have search through google but dint get proper solution, all answers are most welcome Thanks in advance

like image 428
Madhu Avatar asked Apr 08 '26 10:04

Madhu


1 Answers

I did have the same situation. What i have done wrong is that i included getHeaders() in wrong JsonObjectRequest(i.e. with a wrong url). But I used a custom header in my situation. Check your url. It may not be the correct one. It may not accepting this header.

like image 102
SajithK Avatar answered Apr 10 '26 23:04

SajithK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!