mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
add test
This commit is contained in:
parent
9234846eb7
commit
4b2ec7d7a5
@ -25,7 +25,7 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getHttpsTest() {
|
public void getHttpsTest() {
|
||||||
String body = HttpRequest.get("https://www.hutool.cn/").timeout(10).execute().body();
|
final String body = HttpRequest.get("https://www.hutool.cn/").timeout(10).execute().body();
|
||||||
Console.log(body);
|
Console.log(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +41,8 @@ public class HttpRequestTest {
|
|||||||
@Ignore
|
@Ignore
|
||||||
public void getCookiesTest() {
|
public void getCookiesTest() {
|
||||||
// 检查在Connection关闭情况下Cookie是否可以正常获取
|
// 检查在Connection关闭情况下Cookie是否可以正常获取
|
||||||
HttpResponse res = HttpRequest.get("https://www.oschina.net/").execute();
|
final HttpResponse res = HttpRequest.get("https://www.oschina.net/").execute();
|
||||||
String body = res.body();
|
final String body = res.body();
|
||||||
Console.log(res.getCookies());
|
Console.log(res.getCookies());
|
||||||
Console.log(body);
|
Console.log(body);
|
||||||
}
|
}
|
||||||
@ -50,17 +50,17 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void toStringTest() {
|
public void toStringTest() {
|
||||||
String url = "http://gc.ditu.aliyun.com/geocoding?ccc=你好";
|
final String url = "http://gc.ditu.aliyun.com/geocoding?ccc=你好";
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.get(url).body("a=乌海");
|
final HttpRequest request = HttpRequest.get(url).body("a=乌海");
|
||||||
Console.log(request.toString());
|
Console.log(request.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void asyncHeadTest() {
|
public void asyncHeadTest() {
|
||||||
HttpResponse response = HttpRequest.head(url).execute();
|
final HttpResponse response = HttpRequest.head(url).execute();
|
||||||
Map<String, List<String>> headers = response.headers();
|
final Map<String, List<String>> headers = response.headers();
|
||||||
Console.log(headers);
|
Console.log(headers);
|
||||||
Console.log(response.body());
|
Console.log(response.body());
|
||||||
}
|
}
|
||||||
@ -68,24 +68,24 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void asyncGetTest() {
|
public void asyncGetTest() {
|
||||||
TimeInterval timer = DateUtil.timer();
|
final TimeInterval timer = DateUtil.timer();
|
||||||
HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
|
final HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
|
||||||
long interval = timer.interval();
|
final long interval = timer.interval();
|
||||||
timer.restart();
|
timer.restart();
|
||||||
Console.log(body.body());
|
Console.log(body.body());
|
||||||
long interval2 = timer.interval();
|
final long interval2 = timer.interval();
|
||||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void syncGetTest() {
|
public void syncGetTest() {
|
||||||
TimeInterval timer = DateUtil.timer();
|
final TimeInterval timer = DateUtil.timer();
|
||||||
HttpResponse body = HttpRequest.get(url).charset("GBK").execute();
|
final HttpResponse body = HttpRequest.get(url).charset("GBK").execute();
|
||||||
long interval = timer.interval();
|
final long interval = timer.interval();
|
||||||
timer.restart();
|
timer.restart();
|
||||||
Console.log(body.body());
|
Console.log(body.body());
|
||||||
long interval2 = timer.interval();
|
final long interval2 = timer.interval();
|
||||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ public class HttpRequestTest {
|
|||||||
@Ignore
|
@Ignore
|
||||||
public void customGetTest() {
|
public void customGetTest() {
|
||||||
// 自定义构建HTTP GET请求,发送Http GET请求,针对HTTPS安全加密,可以自定义SSL
|
// 自定义构建HTTP GET请求,发送Http GET请求,针对HTTPS安全加密,可以自定义SSL
|
||||||
HttpRequest request = HttpRequest.get(url)
|
final HttpRequest request = HttpRequest.get(url)
|
||||||
// 自定义返回编码
|
// 自定义返回编码
|
||||||
.charset(CharsetUtil.CHARSET_GBK)
|
.charset(CharsetUtil.CHARSET_GBK)
|
||||||
// 禁用缓存
|
// 禁用缓存
|
||||||
@ -106,7 +106,7 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getDeflateTest() {
|
public void getDeflateTest() {
|
||||||
String res = HttpRequest.get("https://comment.bilibili.com/67573272.xml")
|
final String res = HttpRequest.get("https://comment.bilibili.com/67573272.xml")
|
||||||
.execute().body();
|
.execute().body();
|
||||||
Console.log(res);
|
Console.log(res);
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void bodyTest() {
|
public void bodyTest() {
|
||||||
String ddddd1 = HttpRequest.get("https://baijiahao.baidu.com/s").body("id=1625528941695652600").execute().body();
|
final String ddddd1 = HttpRequest.get("https://baijiahao.baidu.com/s").body("id=1625528941695652600").execute().body();
|
||||||
Console.log(ddddd1);
|
Console.log(ddddd1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +124,11 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getLocalTest() {
|
public void getLocalTest() {
|
||||||
List<String> list = new ArrayList<>();
|
final List<String> list = new ArrayList<>();
|
||||||
list.add("hhhhh");
|
list.add("hhhhh");
|
||||||
list.add("sssss");
|
list.add("sssss");
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>(16);
|
final Map<String, Object> map = new HashMap<>(16);
|
||||||
map.put("recordId", "12321321");
|
map.put("recordId", "12321321");
|
||||||
map.put("page", "1");
|
map.put("page", "1");
|
||||||
map.put("size", "2");
|
map.put("size", "2");
|
||||||
@ -143,10 +143,10 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getWithoutEncodeTest() {
|
public void getWithoutEncodeTest() {
|
||||||
String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
final String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
||||||
HttpRequest get = HttpUtil.createGet(url);
|
final HttpRequest get = HttpUtil.createGet(url);
|
||||||
Console.log(get.getUrl());
|
Console.log(get.getUrl());
|
||||||
HttpResponse execute = get.execute();
|
final HttpResponse execute = get.execute();
|
||||||
Console.log(execute.body());
|
Console.log(execute.body());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public class HttpRequestTest {
|
|||||||
// 从5.7.19开始关闭JDK的自动重定向功能,改为手动重定向
|
// 从5.7.19开始关闭JDK的自动重定向功能,改为手动重定向
|
||||||
// 当有多层重定向时,JDK的重定向会失效,或者说只有最后一个重定向有效,因此改为手动更易控制次数
|
// 当有多层重定向时,JDK的重定向会失效,或者说只有最后一个重定向有效,因此改为手动更易控制次数
|
||||||
// 此链接有两次重定向,当设置次数为1时,表示最多执行一次重定向,即请求2次
|
// 此链接有两次重定向,当设置次数为1时,表示最多执行一次重定向,即请求2次
|
||||||
String url = "http://api.rosysun.cn/sjtx/?type=2";
|
final String url = "http://api.rosysun.cn/sjtx/?type=2";
|
||||||
// String url = "https://api.btstu.cn/sjtx/api.php?lx=b1";
|
// String url = "https://api.btstu.cn/sjtx/api.php?lx=b1";
|
||||||
|
|
||||||
// 方式1:全局设置
|
// 方式1:全局设置
|
||||||
@ -188,20 +188,27 @@ public class HttpRequestTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getWithFormTest(){
|
public void getWithFormTest(){
|
||||||
String url = "https://postman-echo.com/get";
|
final String url = "https://postman-echo.com/get";
|
||||||
final Map<String, Object> map = new HashMap<>();
|
final Map<String, Object> map = new HashMap<>();
|
||||||
map.put("aaa", "application+1@qqq.com");
|
map.put("aaa", "application+1@qqq.com");
|
||||||
HttpRequest request =HttpUtil.createGet(url).form(map);
|
final HttpRequest request =HttpUtil.createGet(url).form(map);
|
||||||
Console.log(request.execute().body());
|
Console.log(request.execute().body());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void urlWithParamIfGetTest(){
|
public void urlWithParamIfGetTest(){
|
||||||
UrlBuilder urlBuilder = new UrlBuilder();
|
final UrlBuilder urlBuilder = new UrlBuilder();
|
||||||
urlBuilder.setScheme("https").setHost("hutool.cn");
|
urlBuilder.setScheme("https").setHost("hutool.cn");
|
||||||
|
|
||||||
HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
final HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||||
httpRequest.setMethod(Method.GET).execute();
|
httpRequest.setMethod(Method.GET).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void issueI5Y68WTest() {
|
||||||
|
final HttpResponse httpResponse = HttpRequest.get("http://82.157.17.173:8100/app/getAddress").execute();
|
||||||
|
Console.log(httpResponse.body());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user