Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public String post(String address, String request) {
  2. String response = "";
  3. try {
  4. URL obj = new URL(address);
  5. HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  6. con.setRequestMethod("POST");
  7. con.setRequestProperty("Authorization", authorization);
  8. con.setRequestProperty("Content-Type", "application/json");
  9.  
  10. con.setDoOutput(true);
  11.  
  12. DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  13. wr.writeBytes(request);
  14. wr.flush();
  15. wr.close();
  16.  
  17. BufferedReader in = new BufferedReader(
  18. new InputStreamReader(con.getInputStream()));
  19. String line;
  20. while ((line = in.readLine()) != null) {
  21. response += line;
  22. }
  23. in.close();
  24.  
  25. } catch (IOException e) {
  26. logger.error("HttpsRequestHandler error: " + e.getMessage());
  27. return null;
  28. }
  29. return response;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement