PapaHarni

Webhook

Jun 8th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. URL obj = new URL("URL zum Ziel");
  2. HttpURLConnection con = (HttpURLConnection)obj.openConnection();
  3.  
  4. con.setDoOutput(true);
  5. con.setRequestMethod("POST");
  6.            
  7. con.setRequestProperty("User-Agent", "Java Webhook Class.");
  8. con.setRequestProperty("Content-Type", "application/json");
  9. con.setRequestProperty("Content-Length", "Mein Body ist hier".getBytes().length);
  10. con.setRequestProperty("Accept", "application/json");
  11.  
  12. //Versuch 1
  13. con.getOutputStream().write("Mein Body ist hier".getBytes());
  14. con.getOutputStream().close();
  15.  
  16. //Versuch 2
  17. OutputStreamWriter os = new OutputStreamWriter(con.getOutputStream());
  18. os.write("Mein Body ist hier".getBytes());
  19. os.close();
Advertisement
Add Comment
Please, Sign In to add comment