This commit is contained in:
Looly
2020-10-29 16:19:54 +08:00
parent 19eba6086f
commit 282e1e9090
8 changed files with 39 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.lang.Console;
import cn.hutool.core.net.multipart.UploadFile;
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
public class SimpleServerTest {
@@ -17,9 +18,13 @@ public class SimpleServerTest {
response.write(request.getURI().toString(), ContentType.TEXT_PLAIN.toString())
)
// 返回JSON数据测试
.addAction("/restTest", (request, response) ->
response.write("{\"id\": 1, \"msg\": \"OK\"}", ContentType.JSON.toString())
)
.addAction("/restTest", (request, response) -> {
String res = JSONUtil.createObj()
.set("id", 1)
.set("method", request.getMethod())
.toStringPretty();
response.write(res, ContentType.JSON.toString());
})
// 获取表单数据测试
// http://localhost:8888/formTest?a=1&a=2&b=3
.addAction("/formTest", (request, response) ->

View File

@@ -1,6 +1,7 @@
package cn.hutool.http.test;
import cn.hutool.core.lang.Console;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
@@ -46,8 +47,9 @@ public class RestTest {
@Test
@Ignore
public void postTest3() {
HttpRequest request = HttpRequest.post("http://211.162.39.204:8181/jeesite-simple/a/open/bizGwbnService/test")//
public void getWithBodyTest() {
HttpRequest request = HttpRequest.get("http://localhost:8888/restTest")//
.header(Header.CONTENT_TYPE, "application/json")
.body(JSONUtil.createObj()
.set("aaa", "aaaValue")
.set("键2", "值2").toString());