hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhaohua Meng" <zhaohua.m...@gmail.com>
Subject how to use PostMethod to stream request?
Date Wed, 17 Sep 2008 04:20:30 GMT
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
View raw message