private String volleyPostJsonObjectRequest() { HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("phone", "13429667914"); hashMap.put("key", Constant.JUHE_API_KEY); JSONObject object = new JSONObject(hashMap); JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Constant.JUHE_URL_POST, object, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show(); } }); request.setTag(JSON_OBJECT_POST_TAG); MyApplication.getHttpQueues().add(request); return request.getTag().toString(); }
/** * get请求jsonobject */ private void volleyJsonObjectGet(){ Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show(); Log.d(TAG, "JSONObject-----------" + response.toString()); } }; JsonObjectRequest request = new JsonObjectRequest(Method.GET, url, null, listener, errorListener); request.setTag("jackJsonObjectRequest"); MyApplication.getHttpRequestQueue().add(request); }
private void request(@NonNull Context context, int method, @NonNull String url, @Nullable JSONObject body, @Nullable ApiListener apiListener) { LISession session = LISessionManager.getInstance(context.getApplicationContext()).getSession(); if (!session.isValid()) { if (apiListener != null) { apiListener.onApiError(new LIApiError(LIApiError.ErrorType.accessTokenIsNotSet, "access toke is not set", null)); } return; } JsonObjectRequest jsonObjectRequest = buildRequest(session.getAccessToken().getValue(), method, url, body, apiListener); jsonObjectRequest.setTag(context == null ? TAG : context); QueueManager.getInstance(context).getRequestQueue().add(jsonObjectRequest); }
private String volleyGetJsonObjectRequest() { JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式时,需更改为带请求参数的Object new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show(); } }); request.setTag(JSON_OBJECT_GET_TAG); MyApplication.getHttpQueues().add(request); return request.getTag().toString(); }
/** * ********************************************************************************************** * 得到用户的 汽车列表 */ public static void sendCarInfoPost(JSONObject mParams, final canHandCarInfosPostResult mHand) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, CAR_INFO_POST_URL, mParams, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { mHand.handCarInfosPostResutl(jsonObject); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { mHand.handCarInfosPostError(volleyError); } }); //setTag jsonObjectRequest.setTag(CAR_INFO_POST_TAG); //add MyApplication.getRequestQueue().add(jsonObjectRequest); }
/** * ********************************************************************************************* * 查询订单请求 */ public static void sendMyOrdersPost(JSONObject mParams, final handMyOrdersPost mHand) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, MY_ORDERS_POST_URL, mParams, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { mHand.handMyOrdersPostResult(jsonObject); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { mHand.handMyOrdersPostError(volleyError); } }); //setTag jsonObjectRequest.setTag(MY_ORDERS_POST_TAG); //add MyApplication.getRequestQueue().add(jsonObjectRequest); }
request.setRetryPolicy(new DefaultRetryPolicy(mBuilder.timeOut , mBuilder.retry, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); request.setTag(mBuilder.tag); mQueue.add(request);
request.setTag("jsonPost"); MyApplication.getHttpRequestQueue().add(request);
private void pullUpdateInfo() { //用Volley请求服务器最新的版本信息 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(AUTO_UPDATE_SERVER_ADDRESS, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { paserJsonData(jsonObject); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { volleyError.printStackTrace(); afterUpdate.toDoAfterUpdate(); } }); //设置超时时间,以及重复请求次数 jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(500, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); //设置Tag jsonObjectRequest.setTag(AUTO_UPDATE_SERVER_ADDRESS); //添加到请求队列里面 MyApplication.getRequestQueue().add(jsonObjectRequest); }