1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class Main {
private static InputStream recuperer;
private static OutputStream ecrire;
public static void main(String[] args) {
try {
Socket chaussette = new Socket("www.google.fr",80);
recuperer = chaussette.getInputStream();
ecrire = chaussette.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(ecrire);
osw.write("GET /index.html HTTP/1.0\r\n\r\n");
osw.flush();
int i;
while((i = recuperer.read()) != -1) {
System.out.write(i);
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} |
Partager