本文整理匯總了Java中org.apache.commons.httpclient.methods.PostMethod.getParams方法的典型用法代碼示例。如果您正苦於以下問題:Java PostMethod.getParams方法的具體用法?Java PostMethod.getParams怎麽用?Java PostMethod.getParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.PostMethod
的用法示例。
在下文中一共展示了PostMethod.getParams方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPostFilePart
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
* Test that the body consisting of a file part can be posted.
*/
public void testPostFilePart() throws Exception {
this.server.setHttpService(new EchoService());
PostMethod method = new PostMethod();
byte[] content = "Hello".getBytes();
MultipartRequestEntity entity = new MultipartRequestEntity(
new Part[] {
new FilePart(
"param1",
new ByteArrayPartSource("filename.txt", content),
"text/plain",
"ISO-8859-1") },
method.getParams());
method.setRequestEntity(entity);
client.executeMethod(method);
assertEquals(200,method.getStatusCode());
String body = method.getResponseBodyAsString();
assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
assertTrue(body.indexOf("Hello") >= 0);
}
示例2: testPostStringPart
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
* Test that the body consisting of a string part can be posted.
*/
public void testPostStringPart() throws Exception {
this.server.setHttpService(new EchoService());
PostMethod method = new PostMethod();
MultipartRequestEntity entity = new MultipartRequestEntity(
new Part[] { new StringPart("param", "Hello", "ISO-8859-1") },
method.getParams());
method.setRequestEntity(entity);
client.executeMethod(method);
assertEquals(200,method.getStatusCode());
String body = method.getResponseBodyAsString();
assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param\"") >= 0);
assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
assertTrue(body.indexOf("Content-Transfer-Encoding: 8bit") >= 0);
assertTrue(body.indexOf("Hello") >= 0);
}
示例3: testPostFilePartUnknownLength
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testPostFilePartUnknownLength() throws Exception {
this.server.setHttpService(new EchoService());
String enc = "ISO-8859-1";
PostMethod method = new PostMethod();
byte[] content = "Hello".getBytes(enc);
MultipartRequestEntity entity = new MultipartRequestEntity(
new Part[] {
new FilePart(
"param1",
new TestPartSource("filename.txt", content),
"text/plain",
enc) },
method.getParams());
method.setRequestEntity(entity);
client.executeMethod(method);
assertEquals(200,method.getStatusCode());
String body = method.getResponseBodyAsString();
assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
assertTrue(body.indexOf("Content-Type: text/plain; charset="+enc) >= 0);
assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
assertTrue(body.indexOf("Hello") >= 0);
}
示例4: handleUpload
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void handleUpload(HttpMethod method, Context context) throws EngineException {
if (method instanceof PostMethod) {
try {
PostMethod uploadMethod = (PostMethod) method;
MultipartRequestEntity mp = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), uploadMethod.getParams());
HeaderName.ContentType.setRequestHeader(method, mp.getContentType());
uploadMethod.setRequestEntity(mp);
} catch (Exception e) {
throw new EngineException("(HTTPUploadStatement) failed to handleUpload", e);
}
}
}