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