我已经通过volley实现了post请求。但它有一些奇怪的行为。我收到响应,因为服务器没有响应,但仍然这些发布数据插入数据库两次。 参数是从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);
答案 0 :(得分:0)
我想您在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 ...
}
}
}, ...