當前位置: 首頁>>代碼示例>>Java>>正文


Java PostMethod.setContentChunked方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.methods.PostMethod.setContentChunked方法的典型用法代碼示例。如果您正苦於以下問題:Java PostMethod.setContentChunked方法的具體用法?Java PostMethod.setContentChunked怎麽用?Java PostMethod.setContentChunked使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.methods.PostMethod的用法示例。


在下文中一共展示了PostMethod.setContentChunked方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEnclosedEntityChunked

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityChunked() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:23,代碼來源:TestEntityEnclosingMethod.java

示例2: testEnclosedEntityChunkedHTTP1_0

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityChunkedHTTP1_0() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:22,代碼來源:TestEntityEnclosingMethod.java

示例3: testEnclosedEntityNegativeLength

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityNegativeLength() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例4: testEnclosedEntityNegativeLengthHTTP1_0

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityNegativeLengthHTTP1_0() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:23,代碼來源:TestEntityEnclosingMethod.java

示例5: main

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 1)  {
      System.out.println("Usage: ChunkEncodedPost <file>");
      System.out.println("<file> - full path to a file to be posted");
      System.exit(1);
  }
  HttpClient client = new HttpClient();

  PostMethod httppost = new PostMethod("http://localhost:8080/httpclienttest/body");

  File file = new File(args[0]);

  httppost.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(file)));
  httppost.setContentChunked(true);

  try {
      client.executeMethod(httppost);

      if (httppost.getStatusCode() == HttpStatus.SC_OK) {
          System.out.println(httppost.getResponseBodyAsString());
      } else {
        System.out.println("Unexpected failure: " + httppost.getStatusLine().toString());
      }
  } finally {
      httppost.releaseConnection();
  }   
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:28,代碼來源:ChunkEncodedPost.java

示例6: testEnclosedEntityNonRepeatable

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityNonRepeatable() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));
    this.server.setRequestHandler(handlerchain);
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:29,代碼來源:TestEntityEnclosingMethod.java


注:本文中的org.apache.commons.httpclient.methods.PostMethod.setContentChunked方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。