Package org.apache.http.entity.mime

Examples of org.apache.http.entity.mime.MultipartEntityBuilder.build()


    if (!bodyParts.isEmpty()) {
      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      for (BodyPart bodyPart : bodyParts) {
        bodyPart.addPart(builder);
      }
      return builder.build().toString();
    }
    return null;
  }
 
  /**
 
View Full Code Here


          entityBuilder.addTextBody(contentPart.getName(),
              (String)contentPart.getData(),
              contentPart.getContentType());
        }
      }
      return entityBuilder.build();
    }
   
  }
 
  public static class ContentPart {
View Full Code Here

      builder.addTextBody("successnum", successNum.toString());
    }
    if (picNum != null) {
      builder.addTextBody("picnum", picNum.toString());
    }
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      return Result.parse(json, PicUploadResult.class);
    } catch (ClientProtocolException e) {
View Full Code Here

    addParameter(params, "format", "json");

    for (NameValuePair nameValuePair : params) {
      builder.addTextBody(nameValuePair.getName(), nameValuePair.getValue());
    }
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      JSONObject jsonObject = new JSONObject(json);
      Error error = Error.parse(jsonObject);
View Full Code Here

          builder.addPart(key, new FileBody((File) value));
        } else {
          builder.addPart(key, new StringBody(value.toString(), ContentType.create(ContentType.APPLICATION_FORM_URLENCODED.getMimeType(), Charset.forName(UTF_8))));
        }
      }
      return builder.build();
    } else {
      try {
        return new UrlEncodedFormEntity(MapUtil.getList(parameters), UTF_8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
View Full Code Here

        builder.addBinaryBody("part1", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
        builder.addBinaryBody("part2", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
        StringWriter sw = new StringWriter();
        jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
        builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
        post.setEntity(builder.build());
        HttpResponse response = httpclient.execute(post);
        assertEquals(200, response.getStatusLine().getStatusCode());
    }
   
    @Test
View Full Code Here

        builder.addBinaryBody("part1", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
        builder.addBinaryBody("part2", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
        StringWriter sw = new StringWriter();
        jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
        builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
        post.setEntity(builder.build());
        HttpResponse response = httpclient.execute(post);
        assertEquals(200, response.getStatusLine().getStatusCode());
    }
   
}
View Full Code Here

    params.put("type", typeString);
    ContentBody contentBody = new ByteArrayBody(content, ContentType.MULTIPART_FORM_DATA, "name.jpg");
    entityBuilder.addPart("media", contentBody);
    MediaResultMapper result = WxUtil.sendRequest(
        config.getMediaUploadUrl(), HttpMethod.POST, params,
        entityBuilder.build(), MediaResultMapper.class);

    WxBaseItemMediaEntity resultEntity = null;
    switch (type) {
    case IMAGE:
      WxItemImageEntity imageEntity = new WxItemImageEntity();
View Full Code Here

    URL small = new URL(VideoURLs.map.get("small-webm"));
    FileUtils.copyURLToFile(small, file);
    FileBody fb = new FileBody(file);
    multipartEntity.addPart("file", fb);

    HttpEntity httpEntity = multipartEntity.build();
    post.setEntity(httpEntity);

    EntityUtils.consume(httpEntity);
    HttpResponse response = client.execute(post);
    final int responseStatusCode = response.getStatusLine().getStatusCode();
View Full Code Here

          new StringBody("Ralph", ContentType.DEFAULT_TEXT));
      builder.addPart("age", new StringBody("25", ContentType.DEFAULT_TEXT));
      builder.addPart("email", new StringBody("test@test.ch",
          ContentType.DEFAULT_TEXT));

      post.setEntity(builder.build());
      response = client.execute(post);
      HttpEntity resEntity = response.getEntity();

      assertThat(resEntity).isNotNull();
      String responseString = EntityUtils.toString(resEntity);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.