David, Have a look at this one
http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/PostXML.java?rev=HEAD I suppose it is quite close to what you are trying to accomplish. Another note: we strongly encourage that HttpClient class be used to execute HTTP methods, leaving up to HttpClient to do all the low level connection management. Explicit HTTP connection management is usually discouraged: HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod("http://www.whatever.com/target-url"); try { post.setRequestBody(new FileInputStream(input)); httpclient.executeMethod(post); } finally { post.releaseConnection(); } Hope this helps Cheers Oleg On Wed, 2003-10-01 at 22:04, Jenkins, David wrote: > Hi Oleg, > > I'll include some code fragments that I currently use and code fragments > that I've tried using http client. Maybe you can see where my problems > lie. > **** > HttpURLConnection connection = > (HttpURLConnection)url.openConnection(); > connection.setDoInput(true); > connection.setDoOutput(true); > connection.setUseCaches(false); > connection.setRequestProperty("Content-Type", > "application/x-www-form-urlencoded"); > > ObjectOutputStream oStream = > new ObjectOutputStream(connection.getOutputStream()); > oStream.writeObject(proxy.getClass().getName()); > oStream.writeObject(method.getName()); > if (args != null) { > for (int i = 0; i < args.length; i++) { > oStream.writeObject(args[i]); > } > } > oStream.flush(); > oStream.close(); > > /* Connect and recover any return args*/ > connection.connect(); > **** > I then go on to collect any returned values/exceptions from the > response. > > > This code written for http client simulates a single call > > **** > HttpClient httpClient = new HttpClient(); > HostConfiguration hostConfiguration = new HostConfiguration(); > HttpConnectionManager httpConnectionManager; > > public Main() { > hostConfiguration.setHost("localhost",8080,"http"); > httpClient.setHostConfiguration(hostConfiguration); > httpConnectionManager = httpClient.getHttpConnectionManager(); > doit(); > } > > > public void doit() { > PostMethod post = null; > try { > post = new PostMethod("/fgdam_tst/rPCAction.do"); > post.setDoAuthentication(true); > > Header header = new > Header("content-type",PostMethod.FORM_URL_ENCODED_CONTENT_TYPE); > post.setRequestHeader(header); > > HttpState state = new HttpState(); > > HttpConnection connection = > httpConnectionManager.getConnection(hostConfiguration); > > ObjectOutputStream oos = > new ObjectOutputStream(connection.getRequestOutputStream()); > > oos.writeObject(""); > oos.writeObject("findAllClassifications"); > oos.flush(); > oos.close(); > > post.execute(state,connection); > > if (post.getStatusCode()==HttpStatus.SC_OK) { > ObjectInputStream ois = > new ObjectInputStream(connection.getResponseInputStream()); > Object object = ois.readObject(); > System.out.println(object); > } > else{ > System.out.println(post.getStatusText()); > } > > post.releaseConnection(); > > } > catch (Exception ex) { > ex.printStackTrace(); > } > finally { > post.releaseConnection(); > } > } > > **** > This code results in IOExceptions at the server when trying to read the > request input stream. > > So far I've not found any code in the samples that does exactly what I > want. Or more likely I've just not noticed the code that does exactly > what I want. > > cheers > > Dave > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
