volley get and post
Library used : compile 'com.android.volley:volley:1.0.0'
Post Code :
Post Code :
RequestQueue queue = Volley.newRequestQueue(context); String url = "https://www.2040healthcare.com/app/service-change-password.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // create JSON obj from string try { JSONObject json = new JSONObject(response); String success = json.getString("status"); String response1 = json.getString("response"); String password = json.getString("password"); String user_id = json.getString("status"); System.out.println("response_response" + password +"::"+user_id); } catch (JSONException e) { e.printStackTrace(); } System.out.println("response_response" + response); // _proProgressBar.setVisibility(View.GONE); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { { Toast.makeText(context, "Internet is slow! or Server not responding!", Toast.LENGTH_LONG).show(); } // _proProgressBar.setVisibility(View.GONE); } }) { //adding parameters to the request @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("password", "123456789"); params.put("user_id", "46"); // params.put("password_confirmation", Spassword); return params; } }; queue.add(stringRequest);
Get Code:
RequestQueue queue = Volley.newRequestQueue(context); String url = "http://swaadhyayan.zaptas.com/apicontroll/assessmentreport?assessment_id=2&pre"; StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // create JSON obj from string try { JSONObject json = new JSONObject(response); JSONObject json2 = json.getJSONObject("data"); JSONObject json3 = json2.getJSONObject("ead"); JSONObject json4 = json3.getJSONObject("a"); String total = json4.getString("total"); String number = json4.getString("number"); String percent = json4.getString("percent"); JSONObject json5 = json3.getJSONObject("e"); String total_e = json5.getString("total"); String number_e = json5.getString("number"); String percent_e = json5.getString("percent"); JSONObject json6 = json2.getJSONObject("mi"); // continue............................ System.out.println("check"+total+"::::"+number+":::::"+percent); System.out.println("check"+total_e+"::::"+number_e+":::::"+percent_e); } catch (JSONException e) { e.printStackTrace(); } System.out.println("response_response" + response); dialog.CancelProgressDialog(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { { Toast.makeText(context, "Internet is slow! or Server not responding!", Toast.LENGTH_LONG).show(); } dialog.CancelProgressDialog(); } }) ; queue.add(stringRequest);
Post a Comment