0

I am using volley for login authentication,I passed values to the url by using JSON. Is it Correct Way? if not please tell me how to use POST and GET method in volley Library.i want to authentication to be done using volley library by passing string to the url

 String loginurl = "http://www.souqalkhaleejia.com/webapis/login.php?email="+user+"&password="+pass;
        Log.i("logurl", loginurl);
        JsonObjectRequest loginreq = new JsonObjectRequest(Request.Method.POST, loginurl, (String) null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getString("status").equals("Success")) {
                        String lomsg = response.getString("message");
                        String userid = response.getString("userid");
                        loginsession = new Session(getApplicationContext());
                        loginsession.createLoginSession(user, pass);
                        logineditor.putString("uid", userid);
                        logineditor.commit();
                        if (rememberme.isChecked()) {
                            logineditor.putBoolean("saveboolean", true);
                            logineditor.putString("uname", user);
                            logineditor.putString("pass", pass);
                            logineditor.commit();
                        } else {
                            logineditor.clear();
                            logineditor.commit();
                        }
                        Intent lognext = new Intent(MainActivity.this, Homescreen.class);
                        startActivity(lognext);
                        Toast.makeText(MainActivity.this, ""+lomsg,Toast.LENGTH_SHORT).show();
                    } else {
                        String errmsg = response.getString("message");
                        Toast.makeText(MainActivity.this,""+errmsg,Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(MainActivity.this, "" + error,Toast.LENGTH_SHORT).show();
            }
        });
        AppController.getInstance().addToRequestQueue(loginreq);
    }
Ayub Baba
  • 82
  • 8

1 Answers1

0

You should pass the params like this

RequestQueue queue = Volley.newRequestQueue(context);
    Map<String, String> jsonParams = new HashMap<String, String>();
    jsonParams.put("userId", UserSingleton.getInstance(context).getUserId());
    //jsonParams.put("userId", alert.getUser().getUserId());

    // Request a string response from the provided URL.
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, URL , new JSONObject(jsonParams), new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            //Response OK


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            //Error
        }
    });
Pablo Martinez
  • 1,573
  • 12
  • 31