Damo wrote:
>
> If you type this : www.altavista.com/web/results?q=java into
> the address bar, it will return the result page.
This seems to work (once I managed to spell alta-vista with both Ts -
shouldn't have repeated myself):
import java.io.*;
import java.net.*;
class Search {
public static void main(String[] args) throws Exception {
Socket s = new Socket("www.altavista.com",80);
String request =
"GET /web/results?q=java HTTP/1.1\r\n"+
"Host: www.altavista.com:80\r\n"+
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;rv:1.8.1)
Gecko/20061010 Firefox/2.\r\n"+
"Connection: close\r\n\r\n";
OutputStream out = s.getOutputStream();
out.write(request.getBytes());
out.flush();
InputStream in = s.getInputStream();
for (;

{
int b = in.read();
if (b == -1) { break; }
System.out.print((char)b);
}
}
}
Tom Hawtin