简体   繁体   English

E/Volley:[2342] NetworkUtility.shouldRetryException:意外的响应代码 400

[英]E/Volley: [2342] NetworkUtility.shouldRetryException: Unexpected response code 400

I'm using the Android volley library and I'm trying to sending data to the API server but it responds to this error every time我正在使用 Android volley 库,我正在尝试将数据发送到 API 服务器,但它每次都响应此错误

E/Volley: [2342] NetworkUtility.shouldRetryException: Unexpected response code 400 for API

This is my code:这是我的代码:

       JSONObject params = new JSONObject();
        try {
            params.put("deptcode", 649);
            params.put("endDt", "2021-07-22T12:37:28.755Z");
            params.put("instCode", 152);
            params.put("instSesNO", 0);
            params.put("locCode", 2);
            params.put("observedBy", obserName);
            params.put("sessionId", 0);
            params.put("startDt", "2021-07-22T12:37:28.755Z");
            params.put("status", "string");
        }
        catch (JSONException e) {
            e.printStackTrace();
        }

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                url, params,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("TAG", response.toString());
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("TAG", "Error: " + error.getMessage());
            }
        }) {

            /**
             * Passing some request headers
             * */
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }

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

        MyRequestQueue.add(jsonObjReq);

I tried many ways but still doesn't work for me.我尝试了很多方法,但仍然对我不起作用。 Please help me.请帮我。

normally 400 is a server error that is something not found on server.通常 400 是服务器错误,在服务器上找不到。
1- try your api on postman and verify it is working. 1- 在邮递员上试用您的 api 并验证它是否正常工作。

2- sometimes, the value we're passing in int can be resolved by converting them to string. 2- 有时,我们在 int 中传递的值可以通过将它们转换为字符串来解析。

3- try to get the error message from error.getMessage() . 3- 尝试从error.getMessage()获取错误消息。 if not resolved, please share your api i'll check.如果没有解决,请分享您的api,我会检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM