本文整理汇总了Java中org.apache.http.entity.mime.MultipartEntityBuilder.addTextBody方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartEntityBuilder.addTextBody方法的具体用法?Java MultipartEntityBuilder.addTextBody怎么用?Java MultipartEntityBuilder.addTextBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.entity.mime.MultipartEntityBuilder
的用法示例。
在下文中一共展示了MultipartEntityBuilder.addTextBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if (url != null)
builder.addTextBody(URL_FIELD, url);
if (certificate != null)
builder.addBinaryBody(CERTIFICATE_FIELD, new File(certificate));
if (maxConnections != null)
builder.addTextBody(MAX_CONNECTIONS_FIELD, maxConnections.toString());
if (allowedUpdates != null) {
if (allowedUpdates.length == 0) {
builder.addTextBody(ALLOWED_UPDATES_FIELD, "[]");
} else {
for (String allowedUpdate : allowedUpdates) {
builder.addTextBody(ALLOWED_UPDATES_FIELD + "[]", allowedUpdate);
}
}
}
return builder.build();
}
示例2: setupMultipartEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
private void setupMultipartEntity(HttpPost httpPost){
if(isDebug){
log("Request upload file:"+mFile.getName() +" exists:"+ mFile.exists());
}
MultipartEntityBuilder entity = MultipartEntityBuilder.create()
.seContentType(ContentType.MULTIPART_FORM_DATA)
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.addBinaryBody(mName,mFile,ContentType.DEFAULT_BINARY,mFileName) //uploadFile对应服务端类的同名属性<File类型>
.setCharset(DEFAULT_CHARSET);
for (String key:mFileParames.keySet()) {
String value = mFileParames.get(key);
entity.addTextBody(key,value);
}
httpPost.setEntity(entity.build());
}
示例3: addBody
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {
super.addBody(request, task);
long bytes = 0L;
int idx = 0;
for (File utterance : task.getUtterances()) {
byte[] byteArray = IOUtils.toByteArray(new FileInputStream(utterance));
request.addBinaryBody(REQ_UTTERANCE + (++idx), byteArray);
bytes += byteArray.length;
}
if (task.isFeatureVector()) {
request.addTextBody(REQ_FEATURE_VECTOR, "true");
}
summary.getByteCount().add(bytes);
}
示例4: addBody
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@SneakyThrows
@Override
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {
super.addBody(request, task);
request.addTextBody(REQ_PRINT_NAME, parameters.getPrintName());
request.addTextBody(REQ_CHANNEL, parameters.getChannel());
request.addTextBody(REQ_MODE, parameters.getMode());
String fileName = FilenameUtils.removeExtension(task.getKey());
if (parameters.isTextPrompted()) {
request.addTextBody(REQ_PHRASE, FileUtils.readFileToString(new File(String.format("%s.txt", fileName)), "UTF-8").trim());
request.addTextBody(REQ_VOCAB, parameters.getVocab());
}
}
示例5: PostData
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
static void PostData() throws Exception {
final String url = "https://upload.gyazo.com/api/upload";
final HttpClient httpclient = new Downloader().client;
// create the post request.
final HttpPost httppost = new HttpPost(url);
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
final File f = new File("./src/main/resources/assets/signpic/textures/logo.png");
builder.addBinaryBody("imagedata", f, ContentType.DEFAULT_BINARY, f.getName());
builder.addTextBody("access_token", "4d080e95be741beba0b74653a872668326a79526784d2daed9190dc584bffad7");
httppost.setEntity(builder.build());
// execute request
final HttpResponse response = httpclient.execute(httppost);
final HttpEntity resEntity = response.getEntity();
final InputStream stream = resEntity.getContent();
System.out.println(response.getStatusLine());
System.out.println(convertStreamToString(stream));
}
示例6: post
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public Response post(String url, String auth, JsonJavaObject postData, File fileUpload) throws JsonException, IOException, URISyntaxException {
URI normUri = new URI(url).normalize();
Request postRequest = Request.Post(normUri);
//Add all headers
if(StringUtil.isNotEmpty(auth)) {
postRequest.addHeader("Authorization", auth);
}
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("images_file", fileUpload, ContentType.APPLICATION_OCTET_STREAM, fileUpload.getName());
if(postData != null) {
String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
builder.addTextBody("classifier_ids", postDataString, ContentType.MULTIPART_FORM_DATA);
}
HttpEntity multipart = builder.build();
postRequest.body(multipart);
Response response = executor.execute(postRequest);
return response;
}
示例7: postForm
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
private HttpPost postForm(String url, Map<String, String> params, Map<String, File> files, String charset) {
if (StringUtils.isBlank(charset)) {
charset = "UTF-8";
}
HttpPost httpPost = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if (null != params) {
Set<String> keySet = params.keySet();
for (String key : keySet) {
builder.addTextBody(key, params.get(key), ContentType.create("text/plain", Charset.forName(charset)));
}
}
if (CollectionUtils.isBlank(files)) {
for (String filename : files.keySet()) {
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody(filename, files.get(filename), ContentType.DEFAULT_BINARY, filename);
}
}
httpPost.setEntity(builder.build());
return httpPost;
}
示例8: sendFormToDLMS
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
* * Send POST request to DLMS back end with the result file
* @param bluemixToken - the Bluemix token
* @param contents - the result file
* @param jobUrl - the build url of the build job in Jenkins
* @param timestamp
* @return - response/error message from DLMS
*/
public String sendFormToDLMS(String bluemixToken, FilePath contents, String lifecycleStage, String jobUrl, String timestamp) throws IOException {
// create http client and post method
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost postMethod = new HttpPost(this.dlmsUrl);
postMethod = addProxyInformation(postMethod);
// build up multi-part forms
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
if (contents != null) {
File file = new File(root, contents.getName());
FileBody fileBody = new FileBody(file);
builder.addPart("contents", fileBody);
builder.addTextBody("test_artifact", file.getName());
if (this.isDeploy) {
builder.addTextBody("environment_name", environmentName);
}
//Todo check the value of lifecycleStage
builder.addTextBody("lifecycle_stage", lifecycleStage);
builder.addTextBody("url", jobUrl);
builder.addTextBody("timestamp", timestamp);
String fileExt = FilenameUtils.getExtension(contents.getName());
String contentType;
switch (fileExt) {
case "json":
contentType = CONTENT_TYPE_JSON;
break;
case "xml":
contentType = CONTENT_TYPE_XML;
break;
default:
return "Error: " + contents.getName() + " is an invalid result file type";
}
builder.addTextBody("contents_type", contentType);
HttpEntity entity = builder.build();
postMethod.setEntity(entity);
postMethod.setHeader("Authorization", bluemixToken);
} else {
return "Error: File is null";
}
CloseableHttpResponse response = null;
try {
response = httpClient.execute(postMethod);
// parse the response json body to display detailed info
String resStr = EntityUtils.toString(response.getEntity());
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(resStr);
if (!element.isJsonObject()) {
// 401 Forbidden
return "Error: Upload is Forbidden, please check your org name. Error message: " + element.toString();
} else {
JsonObject resJson = element.getAsJsonObject();
if (resJson != null && resJson.has("status")) {
return String.valueOf(response.getStatusLine()) + "\n" + resJson.get("status");
} else {
// other cases
return String.valueOf(response.getStatusLine());
}
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
示例9: getHttpEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if (chatId != null)
builder.addTextBody(CHAT_ID_FIELD, chatId);
if (media != null) {
builder.addTextBody(MEDIA_FIELD, TelegramObject.gson.toJson(media));
for (InputMedia inputMedia : media) {
if (inputMedia.getFile().isPresent()) {
InputStream file = inputMedia.getFile().get();
String fileAttachName = inputMedia.getFileAttachName()
.orElseThrow(NullPointerException::new);
builder.addBinaryBody(fileAttachName, file, ContentType.APPLICATION_OCTET_STREAM, fileAttachName);
}
}
}
if (disableNotification != null)
builder.addTextBody(DISABLE_NOTIFICATION_FIELD, disableNotification.toString());
if (replyToMessageId != null)
builder.addTextBody(REPLY_TO_MESSAGE_ID_FIELD, replyToMessageId.toString());
return builder.build();
}
示例10: getHttpEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
public HttpEntity getHttpEntity() {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
if(chatId != null)
builder.addTextBody(CHAT_ID_FIELD, chatId);
if(photo != null)
builder.addBinaryBody(PHOTO_FIELD, photo, ContentType.APPLICATION_OCTET_STREAM, fileName);
return builder.build();
}
示例11: createMultipartFormEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
public static HttpEntity createMultipartFormEntity(Map<String, String> parameters, InputStream is) {
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
multipartEntityBuilder.addBinaryBody("file", is, ContentType.create("application/octet-stream"), "file");
for (Entry<String, String> entry : parameters.entrySet()) {
multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
}
return multipartEntityBuilder.build();
}
示例12: createMultipartEntity
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
/**
* Create the required multipart entity
* @param uploadId Session ID
* @return Entity to submit to the upload
* @throws ClientProtocolException
* @throws IOException
*/
protected HttpEntity createMultipartEntity(String uploadId) throws ClientProtocolException, IOException {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("upload_id", uploadId);
builder.addTextBody("_uuid", api.getUuid());
builder.addTextBody("_csrftoken", api.getOrFetchCsrf());
builder.addTextBody("media_type", "2");
builder.setBoundary(api.getUuid());
HttpEntity entity = builder.build();
return entity;
}
示例13: addBody
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {
super.addBody(request, task);
request.addTextBody(REQ_MODE, parameters.getMode());
}
示例14: addBody
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {
super.addBody(request, task);
List<String> ids = parameters.getCrossMatchIds();
String prefix = parameters.getPrefix();
request.addTextBody(REQ_LIST, prefix + StringUtils.join(ids, "," + prefix));
request.addTextBody(REQ_PRINT_NAME, parameters.getPrintName());
request.addTextBody(REQ_CHANNEL, parameters.getChannel());
}
示例15: addBody
import org.apache.http.entity.mime.MultipartEntityBuilder; //导入方法依赖的package包/类
@Override
@SneakyThrows
protected void addBody(MultipartEntityBuilder request, VxmlRequestTask task) {
super.addBody(request, task);
request.addTextBody(REQ_ID, parameters.getPrefix() + task.getKey());
request.addTextBody(REQ_PRINT_NAME, parameters.getPrintName());
request.addTextBody(REQ_CHANNEL, parameters.getChannel());
}