Guest User

Untitled

a guest
Jul 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public void reportSend(View v)
  2. {
  3. th = new Thread(new Runnable() {
  4. @Override
  5. public void run() {
  6. Log.i("TAG","MSG");
  7.  
  8. HttpURLConnection connection = null;
  9. StringBuilder sb = new StringBuilder();
  10. try {
  11.  
  12. connection = (HttpURLConnection) new URL ("http://spaces.ru").openConnection();
  13.  
  14. connection.connect();
  15.  
  16.  
  17. if(connection.HTTP_OK == connection.getResponseCode())
  18. {
  19. BufferedReader input = new BufferedReader(new InputStreamReader( connection.getInputStream(), "cp1251"));
  20.  
  21.  
  22. String line;
  23. while ((line = input.readLine()) != null)
  24. {
  25. sb.append(line);
  26. sb.append("n");
  27. }
  28.  
  29. }
  30.  
  31. }
  32. catch (Exception cause) {
  33. cause.printStackTrace();
  34. // Toast.makeText(MainActivity.this, cause.getMessage().toString(), Toast.LENGTH_LONG).show();
  35. }
  36. finally {
  37. if(connection != null)
  38. connection.disconnect();
  39. }
  40.  
  41.  
  42. Log.i("NET", sb.toString());
  43. }
  44. });
  45.  
  46. th.run();
  47. }
Add Comment
Please, Sign In to add comment