Question
Java: Write a Java program that serves as a primitive web browser. For this assignment it merely needs to input a server name and display
Java: Write a Java program that serves as a primitive web browser. For this assignment it merely needs to input a server name and display the HTML that is sent by the web server. A web server normally listens on port 80. Upon connection the server expects to be sent a string that identifies what web page to receive(use / for the root) and what protocol is used. The next line is the Host and then a blank line. For example, to get the default page on Wikipedia the Java program would connect to port 80 and send: GET / HTTP / 1.1 Host: www.wikipedia.org (blank line) The Wikipedia server would then send back the HTML for the site which your program should display in text.
Can you please not copy and paste this answer:
it doesn't work
1. import java.io.BufferedReader 2. import java.io.IOException; 3. import java.io.InputStreamReader; 4. import java.net.ServerSocket 5. import java.net.Socket; 6. public class SimpleHTTPServer 7. public static void main(String args]) throws IOException 8, ServerSocket server = new ServerSocket(8080); 9. System.out.println("Listening for connection on port 8080.."); 10.while (true) a. Socket clientSocket- server.accept); b. InputStreamReader isr = new InputStreamReader(clientSocket.getlnputStream)) c. BufferedReader reader = new BufferedReader(isr); d. String line reader.readLine); e. while (line.isEmpty)) f. System.out.println (line); g. line=reader-readLine() 12.) 13.) Output: Listening for connection on port 8080 GET/HTTP/1.1 Host: localhost: 8080 User-Agent: Mozilla/5.0 (Windows NT 6.3; WoW64; rv:36.0) Gecko/20100101 Firefox/36.0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started