hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: How to get POST request OutputStream?
Date Sat, 17 May 2003 17:07:54 GMT
As Oleg has said HttpClient uses an input stream for getting content 
instead of a providing an output stream.  To emulate HttpURLConnection 
I can think of a few options.

1) Buffer content to a file or byte array using something like:

ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(someObject);
oos.flush();
PostMethod post = new PostMethod();
post.setRequestBody(new ByteArrayInputStream(os.toByteArray()));

2) Use a PipedOutputStream.  Take a look at 
http://java.sun.com/j2se/1.3/docs/api/java/io/PipedOutputStream.html.  
Be sure to note that the PipedInputStream/OutputStream combo will have 
to be used from different threads.

Mike

On Saturday, May 17, 2003, at 12:45 PM, Sebastian Hauer wrote:

>
> Hi,
>
> I am kind of stuck here.  From the API and browsing through the code I
> don't seem to find a convenient way of obtaining an OutputStream.  I
> need this in order to rewrite some code that is currently using
> Sun's HttpURLConnection that is doing something like this:
>
> ----------------------------------------------
> HttpURLConnection conn = (HttpURLConnection) url.openConnection();
> conn.setRequestMethod("POST");
> OutputStream os = conn.getOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(os);
> oos.writeObject(someObject);
> oos.flush();
> ----------------------------------------------
>
> I will continue to look through the code but I assume I am missing
> something.  Any pointer in the right direction will be appreciated.
>
> Regards,
> Sebastian
>
> <mime-attachment>


Mime
View raw message