commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Kidd <>
Subject RE: HttpClient Usage
Date Wed, 30 Jan 2002 00:52:15 GMT
Thank you for your help Rodney.  I really appreciate it.  

So I could just extend the PostMethod class and add a new method like
writeRequestBody(HttpState state, HttpConnection conn, String body) that
simply calls conn.print(body)?  It seems that is all that I need to do, but
I wanted to be sure since I have next to no experience with these classes.
Thanks in advance for any help.

-----Original Message-----
From: Waldhoff, Rodney []
Sent: Tuesday, January 29, 2002 3:48 PM
To: 'Jakarta Commons Developers List'
Subject: RE: HttpClient Usage

If you want to submit an XML document as the body, I believe what you
want is a PUT not POST method, but you could really do either.

There are a number of examples in the /src/test tree (see
/commons/httpclient/), but here's a snippet for PUT:

  HttpClient client = new HttpClient();
  client.startSession(host, port);
  PutMethod method = new PutMethod("/foo/bar");
  method.setRequestBody("This is data to be sent in the body of an HTTP

I'm pretty sure that the Content-Length value will be calculated
automatically (or chunked output stream will be used).

To POST an arbitrary body (as opposed to a collection of name/value
I think you've got a few options:

A) use PostMethod directly, and add a single parameter containing the
as the name, but no value (e.g.,

B) extend PutMethod such that getName() returns POST  (we could add a
setName method to HttpMethodBase if this is generally useful)

C) extend PostMethod and override writeRequestBody to write your
document as

-----Original Message-----
From: Glenn Kidd []
Sent: Tuesday, January 29, 2002 5:08 PM
To: ''
Subject: HttpClient Usage

Are there any examples out there for using HttpClient to POST?  I looked
around and I could not find any using the newer versions of HttpClient.
need to make a Client that can submit a POST with an XML document as the
body.  As such I need the Content-Length header to get set as well.  Can
anyone point me in the right direction or send a code snippet.  Any help
would be much appreciated.  


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message