// 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.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class XmlUploadString {
    private static void uploadString(String urlstr, String xmlstr) {
        try {
            URL url = new URL(urlstr);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("POST");
            con.setRequestProperty("fnm", "z1.xml");
            con.setDoOutput(true);
            PrintStream ps = new PrintStream(con.getOutputStream(), true, "ISO-8859-1");
            ps.print(xmlstr);
            ps.close();
            con.connect();
            if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
                System.out.println("OK");
            } else {
                System.out.println("Error: " + con.getResponseMessage());
            }
            con.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        uploadString("http://localhost/uploadstr.asp", "<all>\r\n<one>A</one>\r\n<one>BB</one>\r\n<one>CCC</one>\r\n</all>");
    }
}
