Search code examples
androidhttp-postandroid-volleyandroid-networking

Volley server issue


I am running an api which working fine on Postman, but when i am running it thru volley it giving me Server error.

Response: com.android.volley.ServerError

Postman working fine:

enter image description here

Code:

  public  void postNewComment(Context context){
                    String url =     public static final String BASE_URL = "http://api.haebix.in/v1/register";

            RequestQueue queue = Volley.newRequestQueue(context);
            StringRequest sr = new StringRequest(Request.Method.POST,url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d(TAG,response.toString());

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("Error.Response", error.toString());

                }
            }){
                @Override
                protected Map<String,String> getParams(){
                    Map<String,String> params = new HashMap<String, String>();
                    params.put("signup_type", "normal");
                    params.put("name", name);
                    params.put("email", emailID);
                    params.put("password", password);
                    params.put("mobile_no", phoneNo);
                    params.put("promo_code", promocode);
                    params.put("dob", "");
                    params.put("gender", "");
                    params.put("address", "");
                    params.put("city", "");
                    params.put("state", "");
                    params.put("pincode", "");
                    return params;
                }

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String,String> params = new HashMap<String, String>();
                    params.put("Content-Type","application/x-www-form-urlencoded");
                    return params;
                }
            };
            queue.add(sr);
        }

Please help me to find my mistake.


Solution

  • Rewrite url as below: String url = "http://api.haebix.in/v1/register";

    I am getting response : {"error":false,"api_key":"b020bcc9a20c714f2e61c971a9ccd24c","message":"You are successfully registered"}