排球 - POST / GET参数 [英] Volley - POST/GET parameters

查看:225
本文介绍了排球 - POST / GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了谷歌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/

这篇关于排球 - POST / GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆