I was trying to get a web page using Socket and get request but I keep getting the same error - bad request, for any website or webpage i try to use it.
Socket s = new Socket("horstmann.com", 80);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
Scanner reader = new Scanner(in);
PrintWriter writer = new PrintWriter(out, false);
String command = "GET / HTTP/1.0\n\n";
//System.out.print(command);
writer.print(command);
writer.flush();
while (reader.hasNextLine()) {
System.out.println(reader.nextLine());
}
s.close();