排球 - POST / GET参数排球、参数、POST、GET

2023-09-12 00:27:09 作者:犯二吃啥药好呢

我看到了谷歌IO 2013会议关于乱射,我考虑改用凌空。排球是否支持将POST / GET参数要求?如果是的话,我该怎么办呢?

I saw Google IO 2013 session about Volley and I'm considering switching to volley. Does Volley support adding POST/GET parameters to request? If yes, how can I do it?

推荐答案

在你的请求类(即扩展请求),覆盖getParams()方法的方法。你会为标题做相同的,只是重写getHeaders()。

In your Request class (that extends Request), override the getParams() method. You would do the same for headers, just override getHeaders().

如果你看一下TestRequest.java PostWithBody类凌空测试中,你会发现一个例子。 它是这样的

If you look at PostWithBody class in TestRequest.java in Volley tests, you'll find an example. It goes something like 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 = new HashMap<String, String>()
        mParams.put("paramOne", param1);
        mParams.put("paramTwo", param2);

    }

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

埃文·查尔顿是一种足以使一个简单的例子项目向我们展示了如何使用抽射。 https://github.com/evancharlton/folly/

Evan Charlton was kind enough to make a quick example project to show us how to use volley. https://github.com/evancharlton/folly/