本文整理汇总了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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}