我写了一个类,其中包含了排序请求的所有方法,例如GET,POST,PUT。我想从这些方法返回值响应。我无法找到解决方案,因为我无法从onError方法返回响应,例如onErrorResponse和parseNetworkResponse。 PUT方法的代码是,我想从这个方法返回状态代码 -
public static int volleyPutRequest(URL url,JSONObject jsonObject,final Context context){
// Object of request queue
RequestQueue requestQueue;
// Getting the instance of request queue
requestQueue = CustomVolleyRequestQueue.getInstance(context).getRequestQueue();
// Making a JSON request to send the json object to the server
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT,
url.toString(), jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("OnResponse", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("OnErrorResponse", error.toString());
}
}){
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
Log.e("ParseNetworkResponse", String.valueOf(response.statusCode));
return super.parseNetworkResponse(response);
}
};
// Adding the request to the RequestQueue
requestQueue.add(jsonObjectRequest);
}