如何将参数传递给android volley post方法?

时间:2015-12-10 11:30:00

标签: java android post android-volley

我在活动类中定义了一个函数,如下所示:

private void passParam(String pname){
        StringRequest compareRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        //handle response code
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError arg0) {}
        }) {
            @Override
            protected Map<String, String> getParams() {
                //set post params
                Map<String, String> params = new HashMap<String, String>();
                params.put("foo", "foo");
                params.put("name", pname);//Grammar error, want to use parameter pname 
                return params;
            }
        };

        requestQ.add(compareRequest);
    }

我想将post参数“name”值设置为函数pname的参数passParam。如何方便地执行此操作?谢谢!

0 个答案:

没有答案