Hari Roshan
Hari Roshan

Reputation: 384

setting query string in volley is not working

I've tried to send a GET request using my custom request class which inherits request. I've tried to set parameters through getParams() method. But when i send the request I'm getting a username or password invalid error. I have no idea why this is happening. But when i send request through url containing its parameters like http://myurl.com/method?user="username"&password="password" it works.Can somebody tell me why this is happening?

CustomRequest request=new CustomRequest(number,url,new MyListener(number),new ErrorListner(number)){

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> query=new HashMap<>();
                query.put("user",data.getString("user"));
                query.put("password",data.getString("password"));
                query.put("sender",data.getString("senderid"));
                query.put("SMSText",data.getString("message"));
                query.put("GSM",number);
                return  query;

            }
        };

Upvotes: 1

Views: 1685

Answers (1)

enl8enmentnow
enl8enmentnow

Reputation: 943

Reading the javadocs you will see that getParams is only used by POST or PUT, not GET. You need to add the query parameters to the URL yourself.

/**
 * Returns a Map of parameters to be used for a POST or PUT request.  Can throw
 * {@link AuthFailureError} as authentication may be required to provide these values.
 *
 * <p>Note that you can directly override {@link #getBody()} for custom data.</p>
 *
 * @throws AuthFailureError in the event of auth failure
 */
protected Map<String, String> getParams() throws AuthFailureError {
    return null;
}

Upvotes: 3

Related Questions