Volley does not call getParams for my custom request?

前端 未结 3 1063
不知归路
不知归路 2020-12-15 13:07

Please, does Volley automatically add my GET params to the URL? For me it\'s not working so and also when looking into sources, I just cant find any call of the getParams me

相关标签:
3条回答
  • 2020-12-15 13:52

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

     for(String key: params.keySet()) {
       url += "&"+key+"="+params.get(key);
     }
    
    0 讨论(0)
  • 2020-12-15 13:53

    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

    0 讨论(0)
  • 2020-12-15 13:55

    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/

    0 讨论(0)
提交回复
热议问题