POST request writting stream directly

Eduardo Yáñez Parareda <[email protected]> Wed, 29 Jul 2009 14:03:54 +0200
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Hello,

how could I simulate a POST request that writes directly through the
connection?:

            String data = IOUtil.readFile("somefilename.xml");

            URL url = new
URL("http://localhost:50010/custoval/action/create-order");

            // Sets the connection
            HttpURLConnection conexion = (HttpURLConnection)
url.openConnection();
            conexion.setDoOutput(true);
            conexion.setRequestMethod("POST");
            conexion.setRequestProperty("Connection", "Keep-Alive");
            conexion.setRequestProperty("Content-Type", "text/xml");

            // Send the file through the connection
            Writer writer = null;
            writer = new OutputStreamWriter(conexion.getOutputStream());
            writer.write(data);
            writer.flush();
            writer.close();


Before this I have a servlet which read an xml parameter from the
request and it was easy using HttpUnit:

            ServletRunner sr = new ServletRunner(new
File("/home/eyp/workspace/custoval-test/WEB-INF/web.xml"));
            ServletUnitClient sc = sr.newClient();
            WebRequest request = new
PostMethodWebRequest("http://test.meterware.com/action/create-order");
            String xml = IOUtil.readFile("somefile.xml");
>>            request.setParameter("xml", xml); <<
            WebResponse response = sc.getResponse(request);

but without a parameter I don't know how to write the file in the request


Thanks in advance.

Eduardo Yáñez Parareda

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july