Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by f00 on 04.03.15.
- */
- import java.net.*;
- import java.io.*;
- import java.util.*;
- public class HttpGET {
- public static SimpleURL url;
- public void getIt() throws Exception {
- userInput();
- try {
- Socket socket = new Socket(this.getUrl().getHost(), 80);
- System.out.println("Host IP Address: "+ socket.getInetAddress().toString());
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
- out.println("GET "+ this.getUrl().getPath() +" HTTP/1.0");
- out.println(); //leerzeile, RFC norm..
- out.flush();
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String inputLine;
- String[] result = new String[2];
- StringBuilder res = new StringBuilder();
- while ((inputLine = in.readLine()) != null) {
- res.append(inputLine);
- res.append("\n");
- }
- result = res.toString().split("<!");
- in.close();
- System.out.println("################################### REQUEST #####################################");
- System.out.println(result[0]);
- System.out.println("################################### CONTENT #####################################");
- System.out.println(result[1]); // result[0] contains the requestinformation
- socket.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void userInput() {
- System.out.println("Socket Browser v1.0");
- System.out.println("Enter URL:");
- Scanner scanner = new Scanner(System.in);
- SimpleURL newurl = new SimpleURL(scanner.nextLine());
- this.setUrl(newurl);
- System.out.println("connecting to " + this.getUrl().getHost() + "....");
- }
- public SimpleURL getUrl() {
- return url;
- }
- public void setUrl(SimpleURL url) {
- HttpGET.url = url;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement