public static String uploadPicture(String url, String uploadFile) {
    String resultcode = "1";// 0表示成功 ,1表示失败

    HttpClient httpclient = new DefaultHttpClient();

    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

    HttpPost httppost = new HttpPost(url);

    File file = new File(uploadFile); // DEBUG

    MultipartEntity mpEntity = new MultipartEntity();

    ContentBody cbFile = new FileBody(file, "image/jpg");

    ContentBody cbMessage;

    try {

      cbMessage = new StringBody("TEST TSET");

    } catch (UnsupportedEncodingException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      return e.getMessage();

    }

    ContentBody cbAccessToken;

    try {

      cbAccessToken = new StringBody("sfsdfsdf");

    } catch (UnsupportedEncodingException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      return e.getMessage();

    }

mpEntity.addPart("source", cbFile);// 上传文件

    // mpEntity.addPart("message", cbMessage);// 上传信息

    // mpEntity.addPart("access_token", cbAccessToken);// 上传信息

httppost.setEntity(mpEntity); // DEBUG

    HttpResponse response;

    try {

      response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      return e.getMessage();

    } catch (IOException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      return e.getMessage();

    }

    HttpEntity resEntity = response.getEntity(); // DEBUG

    if (resEntity != null) {

      try {

        if (EntityUtils.toString(resEntity) == "1") {

          resultcode = "0";

        }

      } catch (org.apache.http.ParseException e) {

        e.printStackTrace();

        return e.getMessage();

      } catch (IOException e) {

        e.printStackTrace();

        return e.getMessage();

      }

    }

    httpclient.getConnectionManager().shutdown();

    return resultcode;

  }

最新文章

  1. Java 集合类详解
  2. RabbitMQ在window的搭建
  3. 判断是否是有效的IPV4地址
  4. JLINK使用教程详解,以及与JTAG区别
  5. Geographic Coordinate Systems
  6. vim 编辑器笔记
  7. ubuntu 文件编码错误
  8. 【Spring】详解Spring中Bean的加载
  9. Spring Boot 2.x (十五):Dubbo + Zookeeper + 新版Dubbo Admin
  10. golang mysql 的 packet sequence error 这个错
  11. 利用 git format-patch 和 git send-email 把修改的 patch 文件发送给 ffmpeg-devel
  12. ELK 环境搭建2-Kibana
  13. SpringBoot邮件发送
  14. 实战Python实现BT种子转化为磁力链接
  15. LINUX IO 图解
  16. 不错位的java .class 反编译工具推荐
  17. php 扩展包链接
  18. [原][osg][osgEarth]osg::Matrix 父子节点的变化关系
  19. python 拾遗
  20. 数论 + 扩展欧几里得 - SGU 106. The equation

热门文章

  1. java面试 关键字
  2. html5那些事儿
  3. Ubuntu下修改为永久DNS的方法
  4. poj3537 Crosses and Crosses 博弈论
  5. 牛可乐发红包脱单OI赛 C 小可爱表白
  6. 鸟哥的私房菜:Bash shell(三)-命令别名与历史指令
  7. bzoj 3672 利用点分治将CDQ分治推广到树型结构上
  8. poj 1509
  9. Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题
  10. IE11 全新的F12开发者工具