commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Kidd <GK...@placeware.com>
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.


Glenn
-----Original Message-----
From: Waldhoff, Rodney [mailto:rwaldhof@us.britannica.com]
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
really
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
http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/test/org/ap
ache
/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
PUT.");
  client.executeMethod(method);

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
pairs),
I think you've got a few options:

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

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
needed

-----Original Message-----
From: Glenn Kidd [mailto:GKidd@placeware.com]
Sent: Tuesday, January 29, 2002 5:08 PM
To: 'commons-dev@jakarta.apache.org'
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.
I
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.  

Glenn

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message