0
votes

I try everything to solve it but I couldn't. can anybody help me to solve this. I try to login through volley but it gives bad request 400 error, I think it is because of body content type but I also override getbodycontenttype method but it doesn't work, here is code

String url = "http://192.168.1.129:5000/api/dealers/login";

    StringRequest stringRequest = new StringRequest( Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    //progressDialog.dismiss();
                    Log.d("response", response);

                    try {
                        JSONObject data= new JSONObject(response);
                        //Boolean error =jsonObject.getBoolean("error");
                        if (data.getString("success").equals("true")) {

                            String message=data.getString("msg");


                            startActivity( new Intent( LoginActivity.this, MainActivity.class ) );
                            finishAffinity();


                        } else {


                            Toast.makeText(LoginActivity.this,
                                    data.getString("msg"), Toast.LENGTH_LONG).show();

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }



                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            NetworkResponse networkResponse = error.networkResponse;
            if (networkResponse != null) {
                Log.e("Status code", String.valueOf(networkResponse.statusCode));

                Toast.makeText(LoginActivity.this, String.valueOf(networkResponse.statusCode),
                        Toast.LENGTH_SHORT).show();
            }else{
                Log.e("Status code", String.valueOf(error));
                Toast.makeText(LoginActivity.this, String.valueOf(error),
                        Toast.LENGTH_LONG).show();
            }
        }
    }){

        @Override
        public String getBodyContentType() {
            return "application/x-www-form-urlencoded; charset=UTF-8";
        }


        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String,String> params = new HashMap<String, String>();
            params.put("mobile",userMobile);
            params.put("password",userPassword);

            return params;
        }
    };

    int socketTimeout = 0;
    RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

    stringRequest.setRetryPolicy(policy);
    AppController.getInstance().addToRequestQueue(stringRequest);
1

1 Answers

0
votes

Hello
If your server is correct, do this, but when I used this address, I did not receive any data ...
I also made a error in doing a project using it ... it is better to use version of 1.1.0 and before it ...