View: Mostrar por pantalla el codigo de una web

  1. 11 months ago by kuve
    1. public static void main(String[] args) {
    2.         try {
    3.             Socket s = new Socket("http://www.unirioja.es",80);
    4.             BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    5.             BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
    6.             out.write("GET /index.html HTTP/1.0\r\n");
    7.             out.flush();
    8.             String linea;
    9.             while((linea = in.readLine()) != null)
    10.                 System.out.println(linea);
    11.             byte[] buffer = new byte[1024];
    12.             int leidos = 0;
    13.             DataInputStream in2 = new DataInputStream(s.getInputStream());
    14.             leidos = in2.read(buffer);
    15.             while(leidos != -1){
    16.                 System.out.println(buffer.toString());
    17.                 leidos = in2.read(buffer);
    18.             }
    19.         } catch (IOException e) {
    20.             // TODO Auto-generated catch block
    21.             e.printStackTrace();
    22.         }
    23.     }

0 comment about "Mostrar por pantalla el codigo de una web"