commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrea Alberto <andrea.albe...@gmail.com>
Subject Re: [HttpClient] How to output the http request body?
Date Tue, 20 Dec 2005 09:16:29 GMT
Just use
org.apache.commons.httpclient.methods.PostMethod.getRequestBodyAsString()
and
org.apache.commons.httpclient.methods.PostMethod.getResponseBodyAsString()
or the equivalent method of
org.apache.commons.httpclient.methods.GetMethod

To check how to use them from
http://jakarta.apache.org/commons/httpclient/tutorial.html

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    		new DefaultHttpMethodRetryHandler(3, false));

    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);

      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }

      // Read the response body.
      byte[] responseBody = method.getResponseBody();




On 12/20/05, Xiaobo Yang <xiaobo.yang@gmail.com> wrote:
> Hi,
>
> I managed to output the http request head by adding a println statement in
> HttpConnection.java (write method). When I tried to output the http request
> body, I found it to be a OutputStream object. Could anybody tell me how to
> print out the http request body? Also I wonder how to output the http
> response for debugging purpose. Thanks in advanced.
>
> Regards,
> Xiaobo Yang
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message