دوستان کسی راجع به این دو تیکه کد چیزی میدونه ؟ میتونه کمی توضیح بده ؟
Adding Request Headers
String tag_json_obj = "json_obj_req"; String url = "https:// api.androidhive.info/volley/person_object.json"; ProgressDialog pDialog = new ProgressDialog(this); pDialog.setMessage("Loading..."); pDialog.show(); JsonObjectRequest jsonObjReq = new JsonObjectRequest( Method.POST, url, null, new Response.Listener() { @Override public void onResponse(JSONObject response) { Log.d(TAG, response.toString()); pDialog.hide(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); pDialog.hide(); } }) { @Override public Map getHeaders() throws AuthFailureError { HashMap headers = new HashMap(); headers.put("Content-Type", "application/json"); headers.put("apiKey", "xxxxxxxxxxxxxxx"); return headers; } }; AppController.getInstance() .addToRequestQueue(jsonObjReq, tag_json_obj);
Adding Post Parameters
String tag_json_obj = "json_obj_req"; String url = "https:// api.xyz.info/volley/person_object.json"; ProgressDialog pDialog = new ProgressDialog(this); pDialog.setMessage("Loading...PLease wait"); pDialog.show(); JsonObjectRequest jsonObjReq = new JsonObjectRequest( Method.POST, url, null, new Response.Listener() { @Override public void onResponse(JSONObject response) { Log.d(TAG, response.toString()); pDialog.hide(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); pDialog.hide(); } }) { @Override protected Map getParams() { Map params = new HashMap(); params.put("name", "Androidhive"); params.put("email", "abc@androidhive.info"); params.put("password", "password123"); return params; } }; AppController.getInstance() .addToRequestQueue(jsonObjReq, tag_json_obj);