Advertisement

Java 提交同时提交文本表单和上传文件(不依赖第三方库)

阅读量:

在实现文件上传功能的过程中,通常需要对上传行为实施权限验证,此时便需要将文本信息与文件一并提交。

复制代码
 /** * 提交文本参数和上传文件
    
      * * @param postUrl 提交地址
    
      * @param textMap 文本参数
    
      * @param fileMap 文件参数
    
      * @return 上传结果
    
      */
    
     public static String formUpload(String postUrl, Map<String, String> textMap, Map<String, String> fileMap) {
    
     String res = "";
    
     HttpURLConnection conn = null;
    
     String BOUNDARY = "---------------------------" + Long.toHexString(System.currentTimeMillis()); // 随机生成边界字符串
    
     try {
    
         URL url = new URL(postUrl);
    
         conn = (H

全部评论 (0)

还没有任何评论哟~