Example usage for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_CHUNKED

List of usage examples for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_CHUNKED

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_CHUNKED.

Prototype

long CONTENT_LENGTH_CHUNKED

To view the source code for org.apache.commons.httpclient.methods EntityEnclosingMethod CONTENT_LENGTH_CHUNKED.

Click Source Link

Usage

From source file:org.apache.commons.httpclient.demo.PostXMLClient.java

@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {

    File input = new File("test.xml");
    PostMethod post = new PostMethod("http://90.0.12.20:8088/NationWideAdmin/test/PostXMLClient.jsp");

    // // w  ww.  jav  a2 s. co m
    post.setRequestBody(new FileInputStream(input));

    if (input.length() < Integer.MAX_VALUE) {
        post.setRequestContentLength(input.length());
    } else {
        post.setRequestContentLength(EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED);
    }
    // 

    post.setRequestHeader("Content-type", "text/xml; charset=GBK");

    HttpClient httpclient = new HttpClient();
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: ");
    System.out.println(post.getResponseBodyAsString());

    post.releaseConnection();
}