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


Java StringPart.setContentType方法代碼示例

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


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

示例1: buildParts

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入方法依賴的package包/類
private List<Part> buildParts(BaseRequest request) {
    List<Part> parts = new ArrayList<Part>();
    for (PartHolder h : TankHttpUtil.getPartsFromBody(request)) {
        if (h.getFileName() == null) {
            StringPart stringPart = new StringPart(h.getPartName(), new String(h.getBodyAsString()));
            if (h.isContentTypeSet()) {
                stringPart.setContentType(h.getContentType());
            }
            parts.add(stringPart);
        } else {
            PartSource partSource = new ByteArrayPartSource(h.getFileName(), h.getBody());
            FilePart p = new FilePart(h.getPartName(), partSource);
            if (h.isContentTypeSet()) {
                p.setContentType(h.getContentType());
            }
            parts.add(p);
        }
    }
    return parts;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:21,代碼來源:TankHttpClient3.java

示例2: getJsonPostForMultipartRequestEntity

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入方法依賴的package包/類
/**
 * <p>This creates a HttpMethod with the message as its payload and image attachment. The message should be a properly formatted JSON
 * String (No validation is done on this).</p>
 *
 * <p>The message can be easily created using the {@link #getJsonPayload(Message)} method.</p>
 *
 * @param uri The full URI which we will post to
 * @param message A properly formatted JSON message. UTF-8 is expected
 * @param image A complete instance of ImageAttachment object
 * @throws IOException
 */
public HttpMethod getJsonPostForMultipartRequestEntity(String uri, String message, ImageAttachment image) throws IOException {
    PostMethod post = new PostMethod(uri);

    StringPart bodyPart = new StringPart("json", message);
    bodyPart.setContentType("application/json");

    FilePart filePart= new FilePart("feedItemFileUpload", image.retrieveObjectFile());
    filePart.setContentType(image.retrieveContentType());

    Part[] parts = {
            bodyPart,
            filePart,
    };

    post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

    return post;
}
 
開發者ID:forcedotcom,項目名稱:JavaChatterRESTApi,代碼行數:30,代碼來源:ChatterCommands.java

示例3: createStringPart

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入方法依賴的package包/類
private StringPart createStringPart(String name, String value)
{
    StringPart stringPart = new StringPart(name, value);
    stringPart.setContentType(null);
    stringPart.setTransferEncoding(null);
    stringPart.setCharSet("UTF-8");
    return stringPart;
}
 
開發者ID:Alfresco,項目名稱:community-edition-old,代碼行數:9,代碼來源:SlideShareConnectorImpl.java

示例4: uploadContentTypeAssets

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入方法依賴的package包/類
/**
 * This method uploads a content-type asset (ex: wsdl,policy,wadl,swagger)
 * to a running G-Reg instance
 *
 * @param filePath     The absolute path of the file
 * @param fileVersion  Version of the file
 * @param fileName     Name of the file
 * @param shortName    Asset shortname mentioned in the RXT
 * @param cookieHeader Session cookie
 * @throws IOException
 */
public static PostMethod uploadContentTypeAssets(String filePath, String fileVersion, String fileName,
                                                 String shortName, String cookieHeader, String apiUrl)
        throws IOException {

    File file = new File(filePath);
    //The api implementation requires fileUpload name in the format
    //of shortname_file (ex: wsdl_file)
    FilePart fp = new FilePart(shortName + "_file", file);
    fp.setContentType(MediaType.TEXT_PLAIN);
    String version = fileVersion;
    String name = fileName;
    StringPart sp1 = new StringPart("file_version", version);
    sp1.setContentType(MediaType.TEXT_PLAIN);
    StringPart sp2 = new StringPart(shortName + "_file_name", name);
    sp2.setContentType(MediaType.TEXT_PLAIN);
    //Set file parts and string parts together
    final Part[] part = {fp, sp1, sp2};

    HttpClient httpClient = new HttpClient();
    PostMethod httpMethod = new PostMethod(apiUrl);

    httpMethod.addRequestHeader("Cookie", cookieHeader);
    httpMethod.addRequestHeader("Accept", MediaType.APPLICATION_JSON);
    httpMethod.setRequestEntity(
            new MultipartRequestEntity(part, httpMethod.getParams())
    );
    httpClient.executeMethod(httpMethod);
    return httpMethod;
}
 
開發者ID:wso2,項目名稱:product-es,代碼行數:41,代碼來源:FileUploadWithAttachmentUtil.java


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