// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

public class HttpTrad {
    public static void testGET() throws IOException {
        URL url = new URL("http://localhost:81/test.txt");
        URLConnection con = url.openConnection();
        con.connect();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    }
    public static void testPOST() throws IOException {
        URL url = new URL("http://localhost:81/test.php");
        URLConnection con = url.openConnection();
        con.setDoOutput(true);
        con.connect();
        PrintWriter pw = new PrintWriter(con.getOutputStream());
        pw.println("f=123");
        pw.close();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    }
    public static void main(String[] args) throws IOException {
        testGET();
        testPOST();
    }
}
