Advertisement
Sebuahhobi98

post

Sep 3rd, 2021
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public void postData(String relay, String status) {
  2. RequestQueue requestQueue = Volley.newRequestQueue(getContext());
  3. // Enter the correct url for your api service site
  4. try {
  5. JSONObject object = new JSONObject("{}");
  6. //input your API parameters
  7. object.put("relay",relay);
  8. object.put("status",status);
  9. object.put("sn",sn);
  10. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://"+server+"/relay", object,
  11. new Response.Listener<JSONObject>() {
  12. @Override
  13. public void onResponse(JSONObject response) {
  14. Log.e(" POST", "Message: "+response.toString());
  15. try {
  16.  
  17. } catch (Exception e){
  18.  
  19. }
  20. }
  21. }, new Response.ErrorListener() {
  22. @Override
  23. public void onErrorResponse(VolleyError error) {
  24. Log.e("ErrorPOST", "Message: "+error.toString());
  25. }
  26. });
  27. requestQueue.add(jsonObjectRequest);
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. Log.e("Catch POST", e.toString());
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement