本文整理匯總了Java中org.apache.commons.httpclient.methods.InputStreamRequestEntity.CONTENT_LENGTH_AUTO屬性的典型用法代碼示例。如果您正苦於以下問題:Java InputStreamRequestEntity.CONTENT_LENGTH_AUTO屬性的具體用法?Java InputStreamRequestEntity.CONTENT_LENGTH_AUTO怎麽用?Java InputStreamRequestEntity.CONTENT_LENGTH_AUTO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.commons.httpclient.methods.InputStreamRequestEntity
的用法示例。
在下文中一共展示了InputStreamRequestEntity.CONTENT_LENGTH_AUTO屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEnclosedEntityAutoLength
public void testEnclosedEntityAutoLength() 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);
this.server.setHttpService(new EchoService());
try {
this.client.executeMethod(method);
assertEquals(200, method.getStatusCode());
String body = method.getResponseBodyAsString();
assertEquals(inputstr, body);
assertNull(method.getRequestHeader("Transfer-Encoding"));
assertNotNull(method.getRequestHeader("Content-Length"));
assertEquals(input.length, Integer.parseInt(
method.getRequestHeader("Content-Length").getValue()));
} finally {
method.releaseConnection();
}
}
示例2: testEnclosedEntityChunked
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();
}
}
示例3: testEnclosedEntityChunkedHTTP1_0
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();
}
}
示例4: testEnclosedEntityRepeatable
public void testEnclosedEntityRepeatable() 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);
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);
assertEquals(200, method.getStatusCode());
String body = method.getResponseBodyAsString();
assertEquals(inputstr, body);
assertNull(method.getRequestHeader("Transfer-Encoding"));
assertNotNull(method.getRequestHeader("Content-Length"));
assertEquals(input.length, Integer.parseInt(
method.getRequestHeader("Content-Length").getValue()));
} finally {
method.releaseConnection();
}
}
示例5: testEnclosedEntityNonRepeatable
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();
}
}
示例6: create
public static InputData create(String data, Map<String, String> headers) {
return new InputData(null, InputStreamRequestEntity.CONTENT_LENGTH_AUTO, data, headers);
}