public static JSONObject doFormDataPost(File file, String sURL) throws IOException {

        HttpClient context = new DefaultHttpClient();
        HttpPost post = new HttpPost(sURL);
        post.setHeader("user","x");
        post.setHeader("key","x");

        String fileName = "{'filename':'onetime.docx'}";
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addBinaryBody("file", file);//添加文件
        builder.addTextBody("typeid", "29002");  //添加文本类型参数
        builder.addTextBody("data", fileName);  //添加文本类型参数

        post.setEntity(builder.build());
        HttpResponse response = context.execute(post);

        HttpEntity responseEntity = response.getEntity();
        String resEntity= EntityUtils.toString(responseEntity, "UTF-8");
        JSONObject jsonObject = JSONObject.parseObject(resEntity);

        return jsonObject;
    }

 

post请求传文件

相关文章:

  • 2021-09-21
  • 2021-04-29
  • 2022-12-23
  • 2021-08-24
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2022-01-05
  • 2021-04-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案