Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. String url = "http://54.37.137.53:8260/todolist/app/core/action/fixapi.php";
  2. String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
  3. String method = "login";
  4. String login = "admin@admin.pl";
  5. String password = "admin123";
  6. // ...
  7.  
  8. String query = String.format("method=%s&login=%s&password=%s",
  9.      URLEncoder.encode(method, charset),
  10.      URLEncoder.encode(login, charset),
  11.      URLEncoder.encode(password, charset));
  12.  
  13. URLConnection connection = new URL(url).openConnection();
  14. connection.setDoOutput(true); // Triggers POST.
  15. connection.setRequestProperty("Accept-Charset", charset);
  16. connection.setRequestProperty("Content-Type", "application/json;charset=" + charset);
  17.  
  18. try (OutputStream output = connection.getOutputStream()) {
  19.     output.write(query.getBytes(charset));
  20. }
  21.  
  22. InputStream response = connection.getInputStream();
  23.  
  24. System.out.print(response); // W ZMIENNEJ RESPONSE JEST WYNIK, SPRAWDZ CO W NIM SIE ZNAJDUJE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement