android 中 httppost 发送的参数在服务器上被插入为空

Params sent by httppost in android is get inserted as null at server

我正在尝试使用 volley 将参数发送到服务器,即将数据发送到 google 云端点,但在服务器上,插入了空值。我在邮递员身上也试过,

如果我使用 x-www-form-urlencoded,我会在 postman 和 android 中遇到错误:

{
"error": {
    "errors": [
        {
            "domain": "global",
            "reason": "parseError",
            "message": "This API does not support parsing form-encoded input."
        }
    ],
    "code": 400,
    "message": "This API does not support parsing form-encoded input."
}

}

如果我使用表单数据,我会在邮递员中得到我需要的响应。同样,我使用 Content-Type 作为表单数据。但是空值被插入到服务器的数据库中。

我的方法是:

 RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
    // "TAG" used to cancel the request
    String url = "My URL";

    final ProgressDialog pDialog = new ProgressDialog(MainActivity.this);
    pDialog.setMessage("Registering...");
    pDialog.show();

    StringRequest mstringrequest = new StringRequest(Request.Method.DEPRECATED_GET_OR_POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            // mPostCommentResponse.requestCompleted();
            Log.e("TAG", "Service--o/p-" + response);
            pDialog.dismiss();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // mPostCommentResponse.requestEndedWithError(error);
            Log.e("TAG", "Service--i/p-" + error);
            pDialog.dismiss();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("displayEmail", "prachi@gmail.com");
            params.put("displayName", "prachi");
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();


            params.put("Content-Type", "form-data");
            params.put("Content-Disposition", "form-data");


            return params;
        }
    };

    mstringrequest.setRetryPolicy(new DefaultRetryPolicy(
            60000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


    queue.add(mstringrequest);

请帮忙..我哪里错了

我得到了解决方案

 RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
    final ProgressDialog pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Logging In...");
    pDialog.show();

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, Constants.URL_Login, Jsonobj,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    // mPostCommentResponse.requestCompleted();
                    Log.e(TAG, "Service--o/p-" + response);
                    pDialog.dismiss();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // mPostCommentResponse.requestEndedWithError(error);
            Log.e("TAG", "Service--i/p-" + error);
            pDialog.dismiss();

        }
    });
    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
            60000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


    queue.add(jsonObjReq);