Package org.apache.http.entity.mime

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


   * @param addShareBean 参数Bean
   * @return 请求参数
   * @throws UnsupportedEncodingException
   */
  private MultipartEntity getAddSharParam(QqAddShareParamBean addShareBean) throws UnsupportedEncodingException {
    MultipartEntity reqEntity = new MultipartEntity();
   
    // AccessToken
      reqEntity.addPart("access_token", new StringBody(addShareBean.getAccessToken()));
     
      // AppId
      reqEntity.addPart("oauth_consumer_key", new StringBody(oqu.getConfigValue("qq.appid")));
     
      // OpenId
      reqEntity.addPart("openid", new StringBody(addShareBean.getOpenId()));
   
    // 定义API返回的数据格式
      reqEntity.addPart("format", new StringBody("json"));
   
    // feeds的标题
      reqEntity.addPart("title", new StringBody(addShareBean.getTitle(), Charset.forName("UTF-8")));
   
    // 分享所在网页资源的链接
      reqEntity.addPart("url", new StringBody(addShareBean.getUrl()));
   
      // 用户评论内容,也叫发表分享时的分享理由
    if (oqu.isNotNull(addShareBean.getComment())) {
      reqEntity.addPart("comment", new StringBody(addShareBean.getComment(), Charset.forName("UTF-8")));
    }
   
    // 所分享的网页资源的摘要内容
    if (oqu.isNotNull(addShareBean.getSummary())) {
      reqEntity.addPart("summary", new StringBody(addShareBean.getSummary(), Charset.forName("UTF-8")));
    }
   
    // 所分享的网页资源的代表性图片链接
    if (oqu.isNotNull(addShareBean.getImages())) {
      reqEntity.addPart("images", new StringBody(addShareBean.getImages()));
    }
   
    // 分享的场景
    if (oqu.isNotNull(addShareBean.getSource())) {
      // 取值说明:1.通过网页 2.通过手机 3.通过软件 4.通过IPHONE 5.通过 IPAD
      reqEntity.addPart("source", new StringBody(addShareBean.getSource()));
    }
   
    // 分享内容的类型
    if (oqu.isNotNull(addShareBean.getType())) {
      // 4表示网页;5表示视频(type=5时,必须传入playurl)
      reqEntity.addPart("type", new StringBody(addShareBean.getType()));
    }
   
    // 长度限制为256字节。仅在type=5的时候有效。
    if (oqu.isNotNull(addShareBean.getPlayUrl())) {
      reqEntity.addPart("playurl", new StringBody(addShareBean.getPlayUrl()));
    }
   
    // 值为1时,表示分享不默认同步到微博,其他值或者不传此参数表示默认同步到微博。
    if (oqu.isNotNull(addShareBean.getNswb())) {
      reqEntity.addPart("nswb", new StringBody(addShareBean.getNswb()));
    }
   
    return reqEntity;
  }
View Full Code Here


   * @throws IOException
   */
  public QqAddBlogResultBean addOneBlog(QqAddBlogParamBean paramBean) throws JSONException, IOException {

    // 获取接口的参数
    MultipartEntity reqEntity = this.getPostParam(paramBean);
   
    // 接口返回的json数据
    String jsonData = oqu.doPost(OpenQqConstants.QQ_ADD_ONE_BLOG_URL, reqEntity);

    // 返回接口返回的数据
View Full Code Here

   * @return 接口参数
   * @throws UnsupportedEncodingException
   */
  private MultipartEntity getPostParam(QqAddBlogParamBean addBlogBean)
      throws UnsupportedEncodingException {
    MultipartEntity reqEntity = new MultipartEntity();

    // AccessToken
    reqEntity.addPart("access_token", new StringBody(addBlogBean
        .getAccessToken()));

    // AppId
    reqEntity.addPart("oauth_consumer_key", new StringBody(oqu.getConfigValue("qq.appid")));

    // Openid
    reqEntity.addPart("openid", new StringBody(addBlogBean.getOpenId()));

    // 定义API返回的数据格式
    reqEntity.addPart("format", new StringBody("json"));

    // 日志标题
    reqEntity.addPart("title", new StringBody(addBlogBean.getTitle(),
        Charset.forName("UTF-8")));

    // 日志内容
    reqEntity.addPart("content", new StringBody(addBlogBean.getContent(),
        Charset.forName("UTF-8")));

    return reqEntity;
  }
View Full Code Here

            if(haveContentEncoding) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
                            null, charset);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(), charset);
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

            + asConnectionParams.getHost() + ":" + asConnectionParams.getPort() + UPLOAD_URI;
        HttpPost uploadRequest = new HttpPost(uploadUri);
        try {

            // Now upload file with multipart POST request
            MultipartEntity multipartEntity = new MultipartEntity();
            multipartEntity.addPart(filename, new FileBody(cacheFile));
            uploadRequest.setEntity(multipartEntity);
            HttpResponse uploadResponse = httpClient.execute(uploadRequest);
            if (uploadResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                logUploadDoesNotEndWithHttpOkStatus(uploadResponse);
                return null;
View Full Code Here

            if(haveContentEncoding) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
                            null, charset);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(), charset);
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

            if(haveContentEncoding) {
                charset = Charset.forName(contentEncoding);
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
                            null, charset);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               String parameterName = arg.getName();
               if (arg.isSkippable(parameterName)){
                   continue;
               }
               FormBodyPart formPart;
               StringBody stringBody = new StringBody(arg.getValue(), charset);
               formPart = new FormBodyPart(arg.getName(), stringBody);                  
               multiPart.addPart(formPart);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

            if(contentEncoding != null && contentEncoding.length() == 0) {
                contentEncoding = null;
            }

            // Write the request to our own stream
            MultipartEntity multiPart = new MultipartEntity(
                    getDoBrowserCompatibleMultipart() ? HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT);
            // Create the parts
            // Add any parameters
            PropertyIterator args = getArguments().iterator();
            while (args.hasNext()) {
               HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
               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);
            }

            // Add any files
            // Cannot retrieve parts once added to the MultiPartEntity, so have to save them here.
            ViewableFileBody[] fileBodies = new ViewableFileBody[files.length];
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                fileBodies[i] = new ViewableFileBody(new File(file.getPath()), file.getMimeType());
                multiPart.addPart(file.getParamName(),fileBodies[i]);
            }

            post.setEntity(multiPart);

            if (multiPart.isRepeatable()){
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = true;
                }
                multiPart.writeTo(bos);
                for(ViewableFileBody fileBody : fileBodies){
                    fileBody.hideFileData = false;
                }
                bos.flush();
                // We get the posted bytes using the encoding used to create it
View Full Code Here

          } else {
            e = new HttpPost(ha.getRequest());
          }
          e.getParams().setParameter(ClientPNames.DEFAULT_HOST, host);

            MultipartEntity entity = new MultipartEntity();
            for (String key : p.getParams().keySet()) {
              Object content = p.getParams().get(key);
              if (content != null) {
                if (content instanceof String)
                  entity.addPart(key, new StringBody((String) content));
                else if (content instanceof File)
                  entity.addPart(key, new FileBody((File) content));
              }
            }
          ((HttpPost) e).setEntity(entity);
          debug(e, ha, a);
          HttpResponse res = client.execute(e);
View Full Code Here

    HttpPost request = new HttpPost(uri + "/post/create/" + systemID);

    FileBody bin1 = new FileBody(xml, "application/xml; charset=\"UTF-8\"");
    FileBody bin2 = new FileBody(pdf);
    MultipartEntity requestEntity = new MultipartEntity();
    requestEntity.addPart("xml", bin1);
    requestEntity.addPart("prefilled-pdf", bin2);
    request.setEntity(requestEntity);

    HttpResponse response = httpclient.execute(request);
    HttpEntity responseEntity = response.getEntity();
View Full Code Here

TOP

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

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.