// 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.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class PostBig {
    private final static String BOUNDARY = "AVAV"; 
    public static void main(String[] args) throws Exception {
        Socket s = new Socket("localhost", 8080);
        OutputStream os = s.getOutputStream();
        PrintStream ps = new PrintStream(os);
        ps.println("POST /test/xuploaddo.jsp HTTP/1.0");
        ps.println("Host: localhost");
        ps.println("Content-Type: multipart/form-data, boundary=" + BOUNDARY);
        ps.println("Content-Length: 282"); // do yourself a favour and code the upload script so it does not require this
        ps.println("");
        ps.println("--" + BOUNDARY);
        ps.println("Content-Disposition: form-data; name=\"beskrivelse\"");
        ps.println("");
        ps.println("test");
        ps.println("--" + BOUNDARY);
        ps.println("Content-disposition: form-data; name=\"fil\"; filename=\"bigfile.txt\"");
        ps.println("Content-type: text/plain");
        ps.println("");
        for(int i = 0; i < 10; i++) {
            ps.println("Linie #" + i);
        }
        ps.println("--" + BOUNDARY + "--");
        ps.flush();
        InputStream is = s.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }
        ps.close();
        os.close();
        is.close();
        s.close();
    }
}
