Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. String data = "number=123&number2=321"; //данные для отправки
  2. URL myUrl = new URL("https://url");
  3. connection = (HttpURLConnection) myUrl.openConnection();
  4. connection.setDoOutput(true);
  5. connection.setDoInput(true);
  6. connection.setRequestMethod("POST");
  7. //указываем заголовки (как заполнить Content-Length?)
  8. connection.setRequestProperty("Referer", "refererurl");
  9. connection.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
  10. connection.setRequestProperty("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
  11. connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  12. connection.setRequestProperty("Host", "host");
  13. connection.setRequestProperty("Connection", "keep-alive");
  14. connection.connect();
  15. //отправляем данные
  16. DataOutputStream wr = new DataOutputStream( connection.getOutputStream());
  17. wr.writeBytes(data);
  18. wr.flush();
  19. wr.close();
  20.  
  21. InputStream in = connection.getInputStream();
  22. BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
  23. String line = "";
  24. String res = "";
  25.  
  26. while ((line = reader.readLine()) != null) {
  27. res += line;
  28. }
  29. reader.close();
  30. in.close();
  31. textView.setText(res); //выводим в textview
  32. connection.disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement