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/apache /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:[EMAIL PROTECTED]] Sent: Tuesday, January 29, 2002 5:08 PM To: '[EMAIL PROTECTED]' 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
