Package org.apache.http.entity.mime

Examples of org.apache.http.entity.mime.MultipartEntityBuilder


    @Test
    public final void givenCharArrayandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
        final String message = "This is a multipart post";
        final byte[] bytes = "binary code".getBytes();
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", bytes, ContentType.DEFAULT_BINARY, TEXTFILENAME);
        builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here


    this.password = password;
  }

  public Result<String> decode(byte[] img, YundamaType type) {
    HttpPost request = new HttpPost("http://api.yundama.com/api.php?method=upload");
    MultipartEntityBuilder builder =
        MultipartEntityBuilder.create()
            .addBinaryBody("file", img, ContentType.create("image/png"), "code.png")
            .addTextBody("username", username).addTextBody("password", password)
            .addTextBody("codetype", type.getType().toString()).addTextBody("appid", appId)
            .addTextBody("appkey", appKey).addTextBody("timeout", "60");
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      request.releaseConnection();
      JSONObject jsonObject = new JSONObject(json);
View Full Code Here

      com.belerweb.social.weixin.bean.Media media) {
    String url =
        "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + accessToken + "&type="
            + type.value();
    HttpPost request = new HttpPost(url);
    MultipartEntityBuilder builder =
        MultipartEntityBuilder.create().addBinaryBody("media", media.getContent(),
            ContentType.create(media.getContentType()), media.getName());
    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

        nameValuePairList.add(new BasicNameValuePair( "policy""eyJleHBpcmF0aW9uIjogIjIwMTMtMTItMjNUMDk6MjQ6MThaIiwKImNvbmRpdGlvbnMiOiBbeyJ4LWdvb2ctbWV0YS11cGxvYWRlZC1ieSI6ICIzYmFlNDAxMy1kMDNlLTQyN2ItYWMyZS05ZTVkMDg0ZDBlYTkifSx7ImJ1Y2tldCI6ICJja2FubmV0LXN0b3JhZ2UifSx7ImtleSI6ICIyMDEzLTEyLTIyVDEzOjI0OjEyLjg1M1ovdGVzdC54bWwifSx7ImFjbCI6ICJwdWJsaWMtcmVhZCJ9LHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2RhdGFodWIuaW8vc3RvcmFnZS91cGxvYWQvc3VjY2Vzc19lbXB0eT9sYWJlbD0yMDEzLTEyLTIyVDEzJTNBMjQlM0ExMi44NTNaJTJGdGVzdC54bWwifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTAwMDAwMDAwMDBdXX0="));
        nameValuePairList.add(new BasicNameValuePair( "GoogleAccessId""GOOGC6OU3AYPNY47B66M"));
        nameValuePairList.add(new BasicNameValuePair( "signature""VFYngO/4ZQRYt4YXnRGXitiJyNE="));
        nameValuePairList.add(new BasicNameValuePair( "key""2013-12-22T13:24:12.853Z/test97.xml"));

        MultipartEntityBuilder multipartEntityBuilder =
            MultipartEntityBuilder.create();
       
        multipartEntityBuilder.addBinaryBody("test", new File("src/test/resources/org/xmlcml/ckan/test.xml"));
       
        HttpEntity entity = multipartEntityBuilder.build();
        httpPost.setEntity(entity);
       
      //Send request
   
      HttpResponse httpResponse = httpClient.execute(httpPost);
View Full Code Here

        nameValuePairList.add(new BasicNameValuePair( "policy""eyJleHBpcmF0aW9uIjogIjIwMTMtMTItMjNUMDk6MjQ6MThaIiwKImNvbmRpdGlvbnMiOiBbeyJ4LWdvb2ctbWV0YS11cGxvYWRlZC1ieSI6ICIzYmFlNDAxMy1kMDNlLTQyN2ItYWMyZS05ZTVkMDg0ZDBlYTkifSx7ImJ1Y2tldCI6ICJja2FubmV0LXN0b3JhZ2UifSx7ImtleSI6ICIyMDEzLTEyLTIyVDEzOjI0OjEyLjg1M1ovdGVzdC54bWwifSx7ImFjbCI6ICJwdWJsaWMtcmVhZCJ9LHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2RhdGFodWIuaW8vc3RvcmFnZS91cGxvYWQvc3VjY2Vzc19lbXB0eT9sYWJlbD0yMDEzLTEyLTIyVDEzJTNBMjQlM0ExMi44NTNaJTJGdGVzdC54bWwifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTAwMDAwMDAwMDBdXX0="));
        nameValuePairList.add(new BasicNameValuePair( "GoogleAccessId""GOOGC6OU3AYPNY47B66M"));
        nameValuePairList.add(new BasicNameValuePair( "signature""VFYngO/4ZQRYt4YXnRGXitiJyNE="));
        nameValuePairList.add(new BasicNameValuePair( "key""2013-12-22T13:24:12.853Z/test97.xml"));

        MultipartEntityBuilder multipartEntityBuilder =
            MultipartEntityBuilder.create();
       
        multipartEntityBuilder.addBinaryBody("test", new File("src/test/resources/org/xmlcml/ckan/test.xml"));
        for (NameValuePair nvp : nameValuePairList) {
          multipartEntityBuilder.addTextBody(nvp.getName(),  nvp.getValue());
        }
       
        HttpEntity entity = multipartEntityBuilder.build();
        LOG.debug("entity "+entity.getClass()+entity.getContentLength());
       
      httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairList));
        httpPut.setEntity(entity);
       
View Full Code Here

      ArrayList<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
      nameValuePairList.add(new BasicNameValuePair("key",""));
      nameValuePairList.add(new BasicNameValuePair("txtenroll","095020693015"));
      httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList));

        MultipartEntityBuilder multipartEntityBuilder =
            MultipartEntityBuilder.create();
       
        multipartEntityBuilder.addTextBody("foo", "foo body");
        multipartEntityBuilder.addTextBody("foo", "foo body");
        ContentType contentType = ContentType.create("application/octet-stream");
        String filename = "src/test/resources/org/xmlcml/ckan/test.xml";
        File file = new File(filename);
        FileBody fooFileBody = new FileBody(file, contentType);
        // this doesn't compile even though the signatureis offered by Eclipse
//        multipartEntityBuilder.addBinaryBody("foofile", fooFileBody, contentType, filename);
        multipartEntityBuilder.addBinaryBody(filename, new FileInputStream(file), contentType, filename);

        HttpEntity entity = multipartEntityBuilder.build();
        httpPost.setEntity(entity);
       
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity result = response.getEntity();
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.MultipartEntityBuilder

Copyright © 2018 www.massapicom. 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.