// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.net.*;
import java.io.*;

public class BrowserEmu {
   public static void main(String[] args) {
       try {
           System.setProperty("http.proxyHost", "156.24.2.33");
           System.setProperty("http.proxyPort", "8585");
           URL url = new URL("http://www.danbook.com/");
           HttpURLConnection con = (HttpURLConnection) url.openConnection();
           con.setRequestProperty("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
           con.setRequestProperty("Accept-Language", "en-us");
           con.setRequestProperty("Accept-Encoding", "gzip, deflate");
           con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)");
           con.connect();
           int status = con.getResponseCode();
           if (status == HttpURLConnection.HTTP_OK) {
              InputStream is = con.getInputStream();
              System.out.println("Content-Type header = " + con.getContentType());
              System.out.println("Content Length Header = " + con.getContentLength());
              byte[] b = new byte[1000];
              int total = 0;
              int n;
              while ((n = is.read(b)) >= 0) {
                 System.out.println(new String(b, 0, n));
                 total += n;
              }
              is.close();
              System.out.println("Actual length = " + total);
           } else {
              System.out.println("HTTP status = " + status);
           }
           con.disconnect();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
   }
}
