You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Waldhoff, Rodney" <rw...@us.britannica.com> on 2002/04/24 16:17:41 UTC

RE: [httpclient] PostMethod.setRequestBody (was RE: HttpClient Po st)

> According to the documentation, an exception is
> to be thrown if the request body is set and 
> addParameter is to be called. This makes no sense, 
> as there is no way to set the body... 

Not exactly.  There's a protected method of PostMethod called
generateRequestBody, which generates and returns a String containing the
"www-form-urlencoded" name/value pairs.  This is used by
getRequestContentLength() and writeRequestBody() to set the requestBody
attribute.  The javadoc comment is telling you (not very well, apparently)
that it is not valid to invoke addParameter/setParameter, etc. after
generateRequestBody has been called (by getRequestContentLength, by
writeRequestBody, or by some "custom" method defined in a subclass).

> It does, however, prove that the issue was raised at one point...

Well, at the very least, it suggests that it if we add:

public void setRequestBody(String body) {
  requestBody = body;
}

everything should work out OK, since the contract and validation being used
for generateRequestBody can be leveraged here.