簡體   English   中英

E/Volley:[2342] NetworkUtility.shouldRetryException:意外的響應代碼 400

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

我正在使用 Android volley 庫,我正在嘗試將數據發送到 API 服務器,但它每次都響應此錯誤

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

這是我的代碼:

       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);

我嘗試了很多方法,但仍然對我不起作用。 請幫我。

通常 400 是服務器錯誤,在服務器上找不到。
1- 在郵遞員上試用您的 api 並驗證它是否正常工作。

2- 有時,我們在 int 中傳遞的值可以通過將它們轉換為字符串來解析。

3- 嘗試從error.getMessage()獲取錯誤消息。 如果沒有解決,請分享您的api,我會檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM