Hello, how can i make this program run when a user inputs a website, so that it responds with html code. right now when i run it, it just responds with html code from Id like to make it the output like this:
"Please type in a web address" ->(user types in address, and the website html is returned).
Thanks for any help, here is the code I have:
import java.io.*;
import java.net.*;
/**
* will open up a webserver
*
*/
public class SimpleWebClient {
public static void main(String args[])
{
try
{
// open a client socket connection
Socket clientSocket1 = new Socket(" 80);
System.out.println("Client1: " + clientSocket1);
// web page
getPage(clientSocket1);
}
catch (UnknownHostException uhe)
{
System.out.println("UnknownHostException: " + uhe);
}
catch (IOException ioe)
{
System.err.println("IOException: " + ioe);
}
}
/**
* request a Web page
*
*/
public static void getPage(Socket clientSocket)
{
try
{
DataOutputStream outbound = new DataOutputStream(
clientSocket.getOutputStream() );
BufferedReader inbound = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()) );
outbound.writeBytes("GET / HTTP/1.0\r\n\r\n"
String responseLine;
while ((responseLine = inbound.readLine()) != null)
{
// display to the console
System.out.println(responseLine);
}
outbound.close();
inbound.close();
clientSocket.close();
}
catch (IOException ioe)
{
System.out.println("IOException: " + ioe);
}
}
}
"Please type in a web address" ->(user types in address, and the website html is returned).
Thanks for any help, here is the code I have:
import java.io.*;
import java.net.*;
/**
* will open up a webserver
*
*/
public class SimpleWebClient {
public static void main(String args[])
{
try
{
// open a client socket connection
Socket clientSocket1 = new Socket(" 80);
System.out.println("Client1: " + clientSocket1);
// web page
getPage(clientSocket1);
}
catch (UnknownHostException uhe)
{
System.out.println("UnknownHostException: " + uhe);
}
catch (IOException ioe)
{
System.err.println("IOException: " + ioe);
}
}
/**
* request a Web page
*
*/
public static void getPage(Socket clientSocket)
{
try
{
DataOutputStream outbound = new DataOutputStream(
clientSocket.getOutputStream() );
BufferedReader inbound = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()) );
outbound.writeBytes("GET / HTTP/1.0\r\n\r\n"
String responseLine;
while ((responseLine = inbound.readLine()) != null)
{
// display to the console
System.out.println(responseLine);
}
outbound.close();
inbound.close();
clientSocket.close();
}
catch (IOException ioe)
{
System.out.println("IOException: " + ioe);
}
}
}