zoukankan      html  css  js  c++  java
  • 简单纪要:java后台实现 往url上传文件

    将文件 post 到一个上传地址上存储:

      public static void main(String[] args) {
            HttpClient client = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://uploadurl");// 上传地址
            FileBody fileBody = new FileBody(new File("d:\test.mp4"));// 文件位置
            StringBody stringBody;
            try {
                MultipartEntity entity = new MultipartEntity();
                entity.addPart("file", fileBody);
                httpPost.setEntity(entity);
                HttpResponse response = client.execute(httpPost);
                if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
                    // 上传成功
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    hdu 4370
    lightoj 1074
    poj 1026
    poj 3159
    poj3660 cow contest
    hdu 4069 垃圾数独
    操作系统概念题复习
    ARM指令
    C++ 抢占时优先级进程调度
    Docker 入门
  • 原文地址:https://www.cnblogs.com/Rnan/p/10710682.html
Copyright © 2011-2022 走看看