Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. try
  2. {
  3. new AsyncTask<Void, Void, Void>() {
  4.  
  5. @Override
  6. protected Void doInBackground( Void... voids ) {
  7. try
  8. {
  9. URL url = new URL(SERVER_URI + "/notifications/add");
  10. HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
  11. httpCon.setDoOutput(true);
  12. // httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
  13. // httpCon.setRequestMethod("DELETE");
  14. httpCon.setRequestMethod("POST");
  15. httpCon.setRequestProperty("Accept", "application/json");
  16.  
  17. httpCon.connect();
  18. String jsonNotification = new Gson().toJson(notification);
  19. DataOutputStream wr = new DataOutputStream(httpCon.getOutputStream());
  20. wr.writeBytes(jsonNotification);
  21. wr.flush();
  22. wr.close();
  23.  
  24. } catch(IOException e)
  25. {
  26. e.printStackTrace();
  27. }
  28. return null;
  29. }
  30. }.execute().get();
  31. } catch(InterruptedException e)
  32. {
  33. e.printStackTrace();
  34. } catch(ExecutionException e)
  35. {
  36. e.printStackTrace();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement