Volley not calling getParams()
Asked Answered
B

1

2

I am trying to post some parameters to my rails API using Volley in Android. This is the code:

For Request.Method i tried POST/GET/PUT nothing works.

I tried to call a log statement in the getParams() and it was logged, but the params weren't added to the URL.

StringRequest sr = new StringRequest(Request.Method.GET, Links.URL_login, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.d(TAG, response.toString());
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d(TAG, "Error: " + error.getMessage());
                        Log.d(TAG, "" + error.getMessage() + "," + error.toString());
                    }
                }){
                    @Override
                    protected Map<String,String> getParams(){

                        Log.d(TAG, "called?");

                        Map<String, String> params = new HashMap<String, String>();
                        params.put("email", "daniel");
                        params.put("pw", "123");

                        return params;
                    }

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

                    MySingleton.getInstance(getApplicationContext()).addToRequestQueue(sr);
Bifoliolate answered 22/2, 2016 at 12:36 Comment(4)
POST request do not append its param to the URLZebrawood
@OctavianoPutra see my edit still not workingBifoliolate
@vovaxo it's another question and doesn't solve itBifoliolate
Volley not calling getParams(). Please change your subject as they are called as you saw for yourself.Eucaine
E
9

If server is reading as key-value pair then use this

    Uri.Builder builder = Uri.parse(Links.URL_login).buildUpon();
    builder.appendQueryParameter("email", "[email protected]");
    builder.appendQueryParameter("pw", "mypwd");

    String loginUrl=builder.build().toString();
    StringRequest sr = new StringRequest(Request.Method.GET, loginUrl......

And @vovaxo said GET request never call getParams() method.

Eisteddfod answered 22/2, 2016 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.