Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.StringBody


    public void testMultipartRequestToDefaultServlet() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpPost post = new HttpPost(url.toExternalForm() + "/servlet");
            MultipartEntity mp = new MultipartEntity();
            mp.addPart("file", new StringBody(MESSAGE));
            post.setEntity(mp);

            HttpResponse response = httpclient.execute(post);
            HttpEntity entity = response.getEntity();
View Full Code Here


                try {
                    if (!multiPart) {
                        enclodingRequest.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
                    } else {
                        for (NameValuePair nvp : nvps) {
                            multipartEntity.addPart(nvp.getName(), new StringBody(nvp.getValue()));
                        }
                        enclodingRequest.setEntity(multipartEntity);
                    }
                } catch (UnsupportedEncodingException e) {
                    LOG.severe("Could not find UTF-8 encoding, something is really wrong", e);
View Full Code Here

        FileBody bin = new FileBody(new File(fileToUpload));
        try {
            MultipartEntity reqEntity = new MultipartEntity();
            reqEntity.addPart("attachment[file]", bin);
            reqEntity.addPart("attachment[app_id]", new StringBody(appId));
            reqEntity.addPart("attachment[comment]", new StringBody(comment));
            reqEntity.addPart("attachment[type]", new StringBody(type));
            httppost.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
            return resEntity.getContent();
View Full Code Here

               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(),
                       Charset.forName(contentEncoding == null ? "US-ASCII" : contentEncoding));
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }
View Full Code Here

                String p = iter.next();
                String[] vals = params.getParams(p);
                if (vals != null) {
                  for (String v : vals) {
                    if (isMultipart) {
                      parts.add(new FormBodyPart(p, new StringBody(v, Charset.forName("UTF-8"))));
                    } else {
                      postParams.add(new BasicNameValuePair(p, v));
                    }
                  }
                }
View Full Code Here

        HttpPost httppost = new HttpPost("http://localhost:8080" +
                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
View Full Code Here

                String p = iter.next();
                String[] vals = params.getParams(p);
                if (vals != null) {
                  for (String v : vals) {
                    if (isMultipart) {
                      parts.add(new FormBodyPart(p, new StringBody(v, StandardCharsets.UTF_8)));
                    } else {
                      postParams.add(new BasicNameValuePair(p, v));
                    }
                  }
                }
View Full Code Here

        HttpPost httppost = new HttpPost("http://localhost:8080" +
                "/servlets-examples/servlet/RequestInfoExample");

        FileBody bin = new FileBody(new File(args[0]));
        StringBody comment = new StringBody("A binary file of some kind");

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);
        reqEntity.addPart("comment", comment);
       
View Full Code Here

    // Remove blank parameters
    for (Map.Entry<String, Object> param : params.entrySet()) {
      if (param.getValue() instanceof String) {
        String value = (String) param.getValue();
        if (StringUtils.isNotBlank(value)) {
          multipart.addPart(param.getKey(), new StringBody(value));
        }
      } else if (param.getValue() instanceof Collection) {
        for (Object value : (Collection) param.getValue()) {
          multipart.addPart(param.getKey()+"[]", new StringBody(Cloudinary.asString(value)));         
        }
      }
    }

    if (file instanceof String && !((String) file).matches("https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
      file = new File((String) file);
    }
    if (file instanceof File) {
      multipart.addPart("file", new FileBody((File) file));
    } else if (file instanceof String) {
      multipart.addPart("file", new StringBody((String) file));
        } else if (file instanceof byte[]) {
            multipart.addPart("file", new ByteArrayBody((byte[]) file, "file"));
    } else if (file == null) {
        // no-problem
    } else {
View Full Code Here

    // Remove blank parameters
    for (Map.Entry<String, Object> param : params.entrySet()) {
      if (param.getValue() instanceof String) {
        String value = (String) param.getValue();
        if (StringUtils.isNotBlank(value)) {
          multipart.addPart(param.getKey(), new StringBody(value));
        }
      } else if (param.getValue() instanceof Collection) {
        for (Object value : (Collection) param.getValue()) {
          multipart.addPart(param.getKey()+"[]", new StringBody(Cloudinary.asString(value)));         
        }
      }
    }

    if (file instanceof String && !((String) file).matches("^https?:.*")) {
      file = new File((String) file);
    }
    if (file instanceof File) {
      multipart.addPart("file", new FileBody((File) file));
    } else if (file instanceof String) {
      multipart.addPart("file", new StringBody((String) file));
    }
    postMethod.setEntity(multipart);

    HttpResponse response = client.execute(postMethod);
    int code = response.getStatusLine().getStatusCode();
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.StringBody

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.