// 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.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.HttpException;

public class PostXML {
    public static void main(String[] args) throws HttpException, IOException {
        String url = "http://net.xxxx.com/Appl/WebXXXX/xmlservice";
        String body = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?><XXXXRequest CustomerID=\"TEST\"><ProductRequest><Language>ENU</Language><UnitSystem>UC_SI_Units</UnitSystem><Frequency>50</Frequency><ProductNumber>59504539</ProductNumber><QuotationTextWanted>true</QuotationTextWanted><CurveSetWanted>true</CurveSetWanted></ProductRequest></XXXXRequest> ";
        String conttyp = "application/xml; charset=ISO-8859-1";
        System.out.println(url);
        System.out.println(body);
        System.out.println(conttyp);
        try {
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod(url);
            ////post.setRequestBody(body);
            post.setRequestEntity(new StringRequestEntity(body, conttyp, "ISO-8859-1"));
            int result = client.executeMethod(post);
            // Display status code
            System.out.println("Response status code: " + result);
            // Display response
            System.out.println("Response body: ");
            System.out.println(post.getResponseBodyAsString());
            post.releaseConnection();
        } catch (HttpException httpe) {
            httpe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } 
    }
}
