成都创新互联网站制作重庆分公司

Android网络编程之使用HttpClient和MultipartEntityBuilder批量同时上传文件和文字

/** by keinta in China sz  email: hrony@qq.com  2016.10.18
 CN: 此JAR包里面已经集成了android http 网络请求包,也封装了 MultipartEntityBuilder 文件与文字同时上传,实现向下兼容
   你只需要添加这两个包就可以实现android 的多类型网络传输了
    Please add the  packages :
      compile files('libs/org.apache.http.legacy.jar')
    compile files('libs/httpmime-4.3.5.jar')
      compile files('libs/android_httpcore_4.3.2.jar')//  https://pan.baidu.com/s/1i5mEO53
Inside the JAR package has integrated the android HTTP request packet network, also encapsulates the upload MultipartEntityBuilder file with the text at the same time, achieve backward compatibility  
  /**  example 
     * @param context
     * @param url
     * @param filekey
     * @param params
     * @param file
     * @return 
     */
    public String postMutil(Context context, String url, String filekey, final TreeMap params, File file) {
     //  ***省略***
//Image attaching
            MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
            if (file != null && file.exists()) {
                multipartEntity.addBinaryBody(filekey, file, ContentType.MULTIPART_FORM_DATA, file.getName());
            }
//Json string attaching
            for (Map.Entry entry : params.entrySet()) {
                multipartEntity.addPart(entry.getKey(), new StringBody(entry.getValue()));
            }
            httppost.setEntity(multipartEntity.build());
     //   ******省略******

创新互联公司专注于文峰企业网站建设,成都响应式网站建设,商城网站开发。文峰网站建设公司,为文峰等地区提供建站服务。全流程定制开发,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

    }

compile files('libs/android_httpcore_4.3.2.jar')//  https://pan.baidu.com/s/1i5mEO53   包已经上传到百度云可以直接下载用


当前题目:Android网络编程之使用HttpClient和MultipartEntityBuilder批量同时上传文件和文字
本文地址:http://cxhlcq.com/article/gggsoc.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部