Advertisement
Guest User

jsonrqsnip

a guest
Apr 9th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
  2.                     JSONObject object = new JSONObject();
  3.                     try {
  4.                         //input your API parameters
  5.                         object.put("login", ed1.getText());
  6.                         object.put("password", ed2.getText());
  7.                     }
  8.                     catch (JSONException e) {
  9.                         e.printStackTrace();
  10.                     }
  11.                     // Enter the correct url for your api service site
  12.                     String apiUrl = Helper.getConfigValue(MainActivity.super.getApplicationContext(), "api_url");
  13.                     apiUrl = apiUrl + "/auth";
  14.                     JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, apiUrl, object,
  15.                             new Response.Listener<JSONObject>() {
  16.                                 @Override
  17.                                 public void onResponse(JSONObject response) {
  18.                                     apiToken = ("String Response : " + response.toString());
  19.                                     Context context = getApplicationContext();
  20.                                     CharSequence text = apiToken;
  21.                                     int duration = Toast.LENGTH_SHORT;
  22.  
  23.                                     Toast toast = Toast.makeText(context, text, duration);
  24.                                     toast.show();
  25.                                     response.
  26.                                 }
  27.                             }, new Response.ErrorListener() {
  28.                         @Override
  29.                         public void onErrorResponse(VolleyError error) {
  30.  
  31.                             Context context = getApplicationContext();
  32.                             CharSequence text = ""+error.networkResponse;
  33.                             int duration = Toast.LENGTH_SHORT;
  34.  
  35.                             Toast toast = Toast.makeText(context, text, duration);
  36.                             toast.show();
  37.                         }
  38.                     });
  39.                     requestQueue.add(jsonObjectRequest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement