Android POST参数给出了Integrity Constraint Error

时间:2017-04-11 07:18:59

标签: php android post android-volley slim

我正在使用Slim框架POST API,当我将参数从POSTMAN工具发布到post url时它返回响应没有任何问题但是当我尝试从Android发布参数时它给了我错误

{error:{text:SQLSTATE [23000]:Integrity Constraint Voilation,Column不能为空。

我的Andorid代码如下:

StringRequest stringRequest = new StringRequest(Request.Method.POST, "URL_TO_POST",
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                Toast.makeText(AddFeedbackActivity.this, response, Toast.LENGTH_LONG).show();
                            }
                        },
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Toast.makeText(AddFeedbackActivity.this, error.toString(), Toast.LENGTH_LONG).show();
                            }
                        }) {
                    @Override
                    protected Map<String, String> getParams() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("comments", "1");
                        params.put("fname", "1");
                        params.put("mobile_no", "1");
                        return params;
                    }
                };
                RequestQueue requestQueue = Volley.newRequestQueue(AddFeedbackActivity.this);
                requestQueue.add(stringRequest);
            }**

1 个答案:

答案 0 :(得分:0)

这个答案对我有用,现在不给任何错误

            String url = Constant.URL_INSERT_FEEDBACK;

            Map<String, String> params = new HashMap();
            params.put("comments", "1");
            params.put("fname", "1");
            params.put("mobile_no", "1");

            JSONObject parameters = new JSONObject(params);

            JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.POST, url, parameters, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    //TODO: handle success

                    Toast.makeText(AddFeedbackActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    //TODO: handle failure
                    Toast.makeText(AddFeedbackActivity.this, error.toString(), Toast.LENGTH_SHORT).show();

                }
            });

            Volley.newRequestQueue(AddFeedbackActivity.this).add(jsonRequest);


        }