hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yan aka. Yansheng" <yansheng....@gmail.com>
Subject Re: how to use PostMethod to stream request?
Date Wed, 17 Sep 2008 15:27:46 GMT
I had a similar problem.  From what I gathered, HttpClient does not support
stream IO directly.  It's not meant for streaming IO.  So one solution is to
buffer your output locally and send in batch at the end.

Hope this helps.

Yansheng Lin

On Tue, Sep 16, 2008 at 9:20 PM, Zhaohua Meng <zhaohua.meng@gmail.com>wrote:

> I have code snippet like the following. After establishing a
> connection, I need to steam content from database as post body. How do
> I get a OutputStream from either HttpClient or PostMethod? With
> java.net.URL I can use openConnection().getOutputStream(). However I
> want to leverage the nice features of HttpCleint. In the following
> code, I want to call the writeContent() method which should get huge
> data from database.
>
> Any help is appreciated.
>
>        public static void main(String[] args)  throws Exception {
>                HttpClient client = new HttpClient();
>                PostMethod post = new PostMethod("
> http://myhost/service/consumer");
>                try {
>                       //how to get a OutputStream to write my content?
>
>                        int status = client.executeMethod(post);
>
>                        System.out.println(post.getResponseBodyAsString());
>                } finally {
>                        post.releaseConnection();
>                }
>        }
>        public static void writeContent(OutputStream out) throws IOException
> {
>                //data will be generated from database.
>                out.write("<data><value>this</value></data>".getBytes());
>        }
> }
>
> --
> Zhaohua Meng
> zhaohua.meng@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message