Advertisement
Guest User

Untitled

a guest
May 27th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. private static void sendData(List<String> jsonDataPoints) throws IOException {
  2.  
  3. for (String json : jsonDataPoints) {
  4. URL url = new URL(ENDPOINT);
  5. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  6.  
  7. connection.setRequestMethod("POST");
  8. connection.setRequestProperty("Content-Type", "application/json");
  9. connection.setDoOutput(true);
  10.  
  11. DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
  12.  
  13. outputStream.writeBytes(json);
  14. System.out.println("Sending encoded song data to server... ");
  15. System.out.println(json);
  16. outputStream.flush();
  17. int responseCode = connection.getResponseCode();
  18. System.out.println("Response code: " + responseCode);
  19.  
  20.  
  21. outputStream.close();
  22. connection.disconnect();
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement