Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.nio.charset.Charset;
  4.  
  5. public class HelloWorld {
  6.  
  7. public static void main (String[] args) {
  8.  
  9. URL url;
  10. HttpURLConnection connection;
  11. BufferedReader readingData;
  12.  
  13. String requestSite = "http://www.cbr.ru/scripts/XML_daily.asp";
  14. String responseLine;
  15. String responseData = null;
  16.  
  17. try {
  18. url = new URL(requestSite);
  19.  
  20. connection = (HttpURLConnection) url.openConnection();
  21. connection.setRequestMethod("GET");
  22.  
  23. readingData = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  24.  
  25. while ((responseLine = readingData.readLine()) != null) {
  26. responseData += responseLine;
  27. }
  28.  
  29. readingData.close();
  30.  
  31. System.out.println(responseData);
  32.  
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement