Java 类org.apache.commons.httpclient.methods.multipart.PartBase 实例源码

项目:nerd-api    文件:ExtractivClient.java   
private static PostMethod getExtractivProcessString(
                            final URI extractivURI, 
                            final String content,
                            final String serviceKey) throws FileNotFoundException 
{

    final PartBase filePart = new StringPart("content", content, null);

    // bytes to upload
    final ArrayList<Part> message = new ArrayList<Part>();
    message.add(filePart);
    message.add(new StringPart("formids", "content"));
    message.add(new StringPart("output_format", "JSON"));
    message.add(new StringPart("api_key", serviceKey));

    final Part[] messageArray = message.toArray(new Part[0]);

    // Use a Post for the file upload
    final PostMethod postMethod = new PostMethod(extractivURI.toString());
    postMethod.setRequestEntity(new MultipartRequestEntity(messageArray, postMethod.getParams()));
    postMethod.addRequestHeader("Accept-Encoding", "gzip"); // Request the response be compressed (this is highly recommended)

    return postMethod;
}