欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

java 使用 hutool 工具包发送 http post 请求时如何在表单数据正文中传递多个文件类型编号

最编程 2024-03-16 12:31:08
...
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.multipart.FilePart; public class HttpUtilExample { public static void main(String[] args) { // 创建HTTP请求对象 HttpRequest request = HttpRequest.post(" .form("param1", "value1") // 添加其他普通参数 .form("param2", "value2"); // 添加文件参数 FilePart file1 = new FilePart("file1", new File("path/to/file1.jpg")); FilePart file2 = new FilePart("file2", new File("path/to/file2.jpg")); request.part("file1", file1); request.part("file2", file2); // 发送HTTP请求 HttpResponse response = request.execute(); // 处理服务器响应 if (response.isOk()) { System.out.println("上传成功"); } else { System.out.println("上传失败"); } } }