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

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

问题描述

我看过关于 Volley 的 Google IO 2013 会议,我正在考虑改用 Volley.Volley 是否支持向请求添加 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?

推荐答案

在您的 Request 类(扩展 Request)中,覆盖 getParams() 方法.您可以对标头执行相同的操作,只需覆盖 getHeaders().

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

如果您查看 Volley 测试中 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;
    }
}

Evan Charlton 非常友好地制作了一个快速示例项目来向我们展示如何使用截击.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/

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

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