我正在使用此齐射功能来获取响应,但其返回ClientError。 我正在将url-form-encoded参数添加到getBody中,但始终会返回此错误。在将参数添加到getBody中之前,我已将这些参数添加到getParams中,但返回相同的错误。我如何使用这些功能在排球中获取数据
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, URL_API, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse: " + response.toString());
pDialog.hide();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.hide();
Log.d(TAG, "Error: " + error.getMessage());
if( error instanceof NetworkError) {
} else if( error instanceof ServerError) {
} else if( error instanceof AuthFailureError) {
} else if( error instanceof ParseError) {
} else if( error instanceof NoConnectionError) {
} else if( error instanceof TimeoutError) {
}
}
}
){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/x-www-form-urlencoded");
params.put("Authorization", "bearer "+token);
params.put("Accept", "application/json");
return params;
}
@Override
public byte[] getBody() {
Map<String ,String> params=new HashMap<>();
try {
params.put("UG","e550667a-4977-4230-903f-f96efeee0d49");
params.put("IN", "b6ecbcb4a6a64128ba56ec01cb7ffe17.png");
params.put("CMT", "e550667a-4977-4230-903f-f96efeee0d49");
params.put("RID", "1");
}catch (Exception e){
e.printStackTrace();
}
//yeah, I copied this from the base method.
if (params != null && params.size() > 0) {
return encodeParameters(params, getParamsEncoding());
}
return null;
}
};
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
应用此操作后,将返回400 Bad Request错误。