com.android.volley.ClientError和BasicNetwork.performRequest:意外的响应代码400

时间:2019-01-26 07:31:32

标签: java android

我几乎尝试了所有可能的解决方案,但是每次我得到com.android.volley.ClientError和“ BasicNetwork.performRequest:my_api的意外响应代码400”时。我在哪里做错了,请帮忙。和邮递员一起工作很好。 以下是api文档。我还附上了下面的代码。

标题:API_KEY:“我的api密钥” 基本认证 {     “ UserName”:“用户名”,     “密码”:“密码”   } 请求正文     {        “ OrderIds”:[1180782,1180784,1180783],            “ StatusId”:statusId,            “ ThirdPartyId”:30     }

属性数据类型
订单编号列表(整数)
ThirdPartyId int StatusId int

JSONObject jsonBodyObj =新的JSONObject();

    int[] arr = {11111111,22222222};
    List<Integer> list = new ArrayList<>(arr.length);

    for (int i : arr) {
        list.add(Integer.valueOf(i));
    }

    try {
        jsonBodyObj.put("OrderIds",list);
        jsonBodyObj.put("StatusId", 1001);
        jsonBodyObj.put("ThirdPartyId", 30);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    final String requestBody = jsonBodyObj.toString();

JsonObjectRequest jsonObjReq =新的JsonObjectRequest(Request.Method.POST,“ my_url”,                 jsonBodyObj,新Response.Listener()         {

        @Override
        public void onResponse(JSONObject response) {
            Toast.makeText(FulfillmentScanningScreenAjkerDeal.this, "Response" +response, Toast.LENGTH_LONG).show();

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            //VolleyLog.d("Volley error json object ", "Error: " + error.getMessage());
            Toast.makeText(FulfillmentScanningScreenAjkerDeal.this, "Error" +error.getMessage(), Toast.LENGTH_LONG).show();

        }
    })

    {

        @Override
        public byte[] getBody() {
                return requestBody == null ? null : requestBody.getBytes();
        }

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

            headers.put("Authorization", "Basic my_auth_key");
            headers.put("API_KEY", "my_Api_key");
            headers.put("Content-Type", "application/json");

            return headers;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.getCache().clear();
    requestQueue.add(jsonObjReq);

0 个答案:

没有答案