mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add body
This commit is contained in:
@@ -27,11 +27,13 @@ public class SimpleServerTest {
|
||||
// 文件上传测试
|
||||
// http://localhost:8888/formTest?a=1&a=2&b=3
|
||||
.addAction("/file", (request, response) -> {
|
||||
final UploadFile file = request.getMultipart().getFile("file");
|
||||
final UploadFile[] files = request.getMultipart().getFiles("file");
|
||||
// 传入目录,默认读取HTTP头中的文件名然后创建文件
|
||||
file.write("d:/test/");
|
||||
Console.log("Write file to: d:/test/");
|
||||
response.write(request.getParams().toString(), ContentType.TEXT_PLAIN.toString());
|
||||
for (UploadFile file : files) {
|
||||
file.write("d:/test/");
|
||||
Console.log("Write file: d:/test/" + file.getFileName());
|
||||
}
|
||||
response.write(request.getMultipart().getParamMap().toString(), ContentType.TEXT_PLAIN.toString());
|
||||
}
|
||||
)
|
||||
.start();
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package cn.hutool.http.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 文件上传单元测试
|
||||
@@ -24,16 +24,16 @@ public class UploadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadFilesTest() {
|
||||
File file = FileUtil.file("e:\\face.jpg");
|
||||
File file2 = FileUtil.file("e:\\face2.jpg");
|
||||
File file = FileUtil.file("d:\\图片1.JPG");
|
||||
File file2 = FileUtil.file("d:\\图片3.png");
|
||||
|
||||
// 方法一:自定义构建表单
|
||||
HttpRequest request = HttpRequest//
|
||||
.post("http://localhost:8090/file/upload")//
|
||||
.post("http://localhost:8888/file")//
|
||||
.form("file", file2, file)//
|
||||
.form("fileType", "图片");
|
||||
HttpResponse response = request.execute();
|
||||
System.out.println(response.body());
|
||||
Console.log(response.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user