httpsost在android中发送的参数在服务器上作为null插入

时间:2016-11-30 12:59:01

标签: android android-volley google-cloud-endpoints

我正在尝试使用volley向服务器发送params,即将数据发送到google云端点,但是在服务器上,插入了null值。我在邮递员身上尝试过同样的事情,

如果我使用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);

请帮助......我错了

1 个答案:

答案 0 :(得分:1)

我得到了解决方案

Add-Member -InputObject $eventlog -Name Hostname -Value $env:COMPUTERNAME