S
stan k.
The example below works fine. It browses a url and then prints it out
one line at a time to the screen as the user presses enter. This might
sound like too easy a question but how to I adjust this to make it
automatically display itself to the screen, or better yet, copy the
whole contents to a string variable...
I am totally stuck on this, sorry if i am asking a stupid question
here, maybe
it's just a small change needed
------------
import java.io.*;
import java.net.*;
public class webpagedownloader{
public static void main(String[] args) throws IOException {
Socket sock = null;
PrintWriter out = null;
BufferedReader in = null;
try{
sock = new Socket("www.whatever", 80);
out = new PrintWriter(sock.getOutputStream(), true);
out.print("GET /yourlife/deleteme.html \r\n User-Agent: Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1) \r\n HOST: www.whatever.com
\r\n\r\n");
in = new BufferedReader(new
InputStreamReader(sock.getInputStream()));
}catch(UnknownHostException e){
System.err.println("can't find host");
System.exit(1);
}catch(IOException e){
System.err.println("Couldn't make i/o connection to server");
System.exit(1);
}//try-catch-catch
BufferedReader stdIn = new BufferedReader(new
InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}//while
out.close();
in.close();
stdIn.close();
sock.close();
}//main()
}
one line at a time to the screen as the user presses enter. This might
sound like too easy a question but how to I adjust this to make it
automatically display itself to the screen, or better yet, copy the
whole contents to a string variable...
I am totally stuck on this, sorry if i am asking a stupid question
here, maybe
it's just a small change needed
------------
import java.io.*;
import java.net.*;
public class webpagedownloader{
public static void main(String[] args) throws IOException {
Socket sock = null;
PrintWriter out = null;
BufferedReader in = null;
try{
sock = new Socket("www.whatever", 80);
out = new PrintWriter(sock.getOutputStream(), true);
out.print("GET /yourlife/deleteme.html \r\n User-Agent: Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1) \r\n HOST: www.whatever.com
\r\n\r\n");
in = new BufferedReader(new
InputStreamReader(sock.getInputStream()));
}catch(UnknownHostException e){
System.err.println("can't find host");
System.exit(1);
}catch(IOException e){
System.err.println("Couldn't make i/o connection to server");
System.exit(1);
}//try-catch-catch
BufferedReader stdIn = new BufferedReader(new
InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}//while
out.close();
in.close();
stdIn.close();
sock.close();
}//main()
}