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


Java PostMethod.getParams方法代碼示例

本文整理匯總了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);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:29,代碼來源:TestMultipartPost.java

示例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);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:22,代碼來源:TestMultipartPost.java

示例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);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:27,代碼來源:TestMultipartPost.java

示例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);
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:13,代碼來源:HTTPUploadStatement.java


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