[英]Android Volley Post Request
我已经通过截击实现了发帖请求,但是它有一些奇怪的行为。 我得到响应,因为服务器未响应,但是仍然将那些发布数据两次插入数据库。 这些参数是简单字符串类型的数据,这些数据是从edittext字段中获取的。
StringRequest stringRequest = new StringRequest(Request.Method.POST, GlobalConfig.ADD_ACTIVITY_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
Log.e("response", response);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
GlobalCommonMethods.handleErrorResponse(ActivityTeacher.this,error,"Server not responding !!!");
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> arguments = new HashMap<String, String>();
arguments.put("teacher_id", "ds";
arguments.put("action", "comment");
arguments.put("user_type", "teacher");
return arguments;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
我猜您错过了catch() {...}
之前的try {...}
catch() {...}
。 下面是我的意思的示例:
StringRequest stringRequest = new StringRequest(Request.Method.POST, GlobalConfig.ADD_ACTIVITY_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Something here...
} catch (JSONException e) {
Something here ...
}
}
}, ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.