【发布时间】:2013-10-15 15:04:56
【问题描述】:
我想使用 Volley 从设备到服务器 POST JsonObject,但我找不到任何代码示例。如果可以,请为我提供一些参考资料或一些代码示例。
【问题讨论】:
标签: android json http-post android-volley androidhttpclient
我想使用 Volley 从设备到服务器 POST JsonObject,但我找不到任何代码示例。如果可以,请为我提供一些参考资料或一些代码示例。
【问题讨论】:
标签: android json http-post android-volley androidhttpclient
我是这样做的
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);
}
【讨论】:
我找到了一个很好的参考,哪里有一些很好的例子:
【讨论】: