Volley does not call getParams for my custom request?

拈花ヽ惹草 提交于 2019-11-29 00:16:56

getParams() is not called on the GET method, so it seems you'll have to add it to the URL before you send the request.

Check out the JavaDoc:

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.

Note that you can directly override {@link #getBody()} for custom data.

@throws AuthFailureError in the event of auth failure

arufian

As for Itai Hanski answer, this is one example to implement that:

 for(String key: params.keySet()) {
   url += "&"+key+"="+params.get(key);
 }

Try this,

public class LoginRequest extends Request<String> {

    // ... other methods go here

    private Map<String, String> mParams;

    public LoginRequest(String param1, String param2, Listener<String> listener, ErrorListener errorListener) {
        super(Method.POST, "http://test.url", errorListener);
        mListener = listener;
        mParams.put("paramOne", param1);
        mParams.put("paramTwo", param2);

    }

    @Override
    public Map<String, String> getParams() {
        return mParams;
    }
}

See this example also,

https://github.com/evancharlton/folly/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!