【问题标题】:Android Volley JsonRequest [closed]Android Volley JsonRequest [关闭]
【发布时间】:2013-10-15 15:04:56
【问题描述】:

我想使用 Volley 从设备到服务器 POST JsonObject,但我找不到任何代码示例。如果可以,请为我提供一些参考资料或一些代码示例。

【问题讨论】:

    标签: android json http-post android-volley androidhttpclient


    【解决方案1】:

    我是这样做的

    public void doRequest(RequestQueue volleyRequestQueue,
            onResponse responseListener) {
    
        this._responseListener = responseListener;
    
        StringRequest stringRequest = new StringRequest(Method.POST,
                Settings.QUESTIONURL, this, this) {
    
            public String getBodyContentType() {
                return "application/json; charset=" + getParamsEncoding();
            }
    
            public byte[] getBody() throws AuthFailureError {
                try {
                    return new GsonBuilder()
                            .excludeFieldsWithoutExposeAnnotation().create()
                            .toJson(YOUROBJECT).toString()
                            .getBytes(getParamsEncoding());
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return null;
            }
    
        };
    
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10000, MAXRETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    
        volleyRequestQueue.add(stringRequest);
    }
    

    【讨论】:

      【解决方案2】:

      我找到了一个很好的参考,哪里有一些很好的例子:

      Link

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-23
        • 1970-01-01
        • 2017-06-08
        • 2017-08-19
        • 1970-01-01
        • 2017-06-25
        • 2013-11-29
        相关资源
        最近更新 更多