mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -13,7 +13,7 @@ public class ContentTypeTest {
|
||||
|
||||
@Test
|
||||
public void testBuild() {
|
||||
String result = ContentType.build(ContentType.JSON, CharsetUtil.UTF_8);
|
||||
final String result = ContentType.build(ContentType.JSON, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("application/json;charset=UTF-8", result);
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ public class DownloadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void downloadPicTest() {
|
||||
String url = "http://wx.qlogo.cn/mmopen/vKhlFcibVUtNBVDjcIowlg0X8aJfHXrTNCEFBukWVH9ta99pfEN88lU39MKspCUCOP3yrFBH3y2NbV7sYtIIlon8XxLwAEqv2/0";
|
||||
final String url = "http://wx.qlogo.cn/mmopen/vKhlFcibVUtNBVDjcIowlg0X8aJfHXrTNCEFBukWVH9ta99pfEN88lU39MKspCUCOP3yrFBH3y2NbV7sYtIIlon8XxLwAEqv2/0";
|
||||
HttpUtil.downloadFile(url, "e:/pic/t3.jpg");
|
||||
Console.log("ok");
|
||||
}
|
||||
@@ -29,14 +29,14 @@ public class DownloadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void downloadSizeTest() {
|
||||
String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg";
|
||||
final String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg";
|
||||
HttpRequest.get(url).setSSLProtocol("TLSv1.2").executeAsync().writeBody("e:/pic/366466.jpg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void downloadTest1() {
|
||||
long size = HttpUtil.downloadFile("http://explorer.bbfriend.com/crossdomain.xml", "e:/temp/");
|
||||
final long size = HttpUtil.downloadFile("http://explorer.bbfriend.com/crossdomain.xml", "e:/temp/");
|
||||
System.out.println("Download size: " + size);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public class DownloadTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(long contentLength, long progressSize) {
|
||||
long speed = progressSize / (System.currentTimeMillis() - time) * 1000;
|
||||
public void progress(final long contentLength, final long progressSize) {
|
||||
final long speed = progressSize / (System.currentTimeMillis() - time) * 1000;
|
||||
Console.log("总大小:{}, 已下载:{}, 速度:{}/s", FileUtil.readableFileSize(contentLength), FileUtil.readableFileSize(progressSize), FileUtil.readableFileSize(speed));
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DownloadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void downloadFileFromUrlTest1() {
|
||||
File file = HttpUtil.downloadFileFromUrl("http://groovy-lang.org/changelogs/changelog-3.0.5.html", "d:/download/temp");
|
||||
final File file = HttpUtil.downloadFileFromUrl("http://groovy-lang.org/changelogs/changelog-3.0.5.html", "d:/download/temp");
|
||||
Assert.assertNotNull(file);
|
||||
Assert.assertTrue(file.isFile());
|
||||
Assert.assertTrue(file.length() > 0);
|
||||
@@ -87,7 +87,7 @@ public class DownloadTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(long contentLength, long progressSize) {
|
||||
public void progress(final long contentLength, final long progressSize) {
|
||||
System.out.println("download size:" + progressSize);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class DownloadTest {
|
||||
Assert.assertTrue(file.isFile());
|
||||
Assert.assertTrue(file.length() > 0);
|
||||
Assert.assertTrue(file.getName().length() > 0);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Assert.assertTrue(e instanceof IORuntimeException);
|
||||
} finally {
|
||||
FileUtil.del(file);
|
||||
@@ -121,7 +121,7 @@ public class DownloadTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(long contentLength, long progressSize) {
|
||||
public void progress(final long contentLength, final long progressSize) {
|
||||
System.out.println("contentLength:" + contentLength + "download size:" + progressSize);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class DownloadTest {
|
||||
Assert.assertTrue(file.isFile());
|
||||
Assert.assertTrue(file.length() > 0);
|
||||
Assert.assertTrue(file.getName().length() > 0);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Assert.assertTrue(e instanceof IORuntimeException);
|
||||
} finally {
|
||||
FileUtil.del(file);
|
||||
|
@@ -118,26 +118,26 @@ public class HtmlUtilTest {
|
||||
@Test
|
||||
public void unwrapTest2() {
|
||||
// 避免移除i却误删img标签的情况
|
||||
String htmlString = "<html><img src='aaa'><i>测试文本</i></html>";
|
||||
String tagString = "i,br";
|
||||
String cleanTxt = HtmlUtil.removeHtmlTag(htmlString, false, tagString.split(","));
|
||||
final String htmlString = "<html><img src='aaa'><i>测试文本</i></html>";
|
||||
final String tagString = "i,br";
|
||||
final String cleanTxt = HtmlUtil.removeHtmlTag(htmlString, false, tagString.split(","));
|
||||
Assert.assertEquals("<html><img src='aaa'>测试文本</html>", cleanTxt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapeTest() {
|
||||
String html = "<html><body>123'123'</body></html>";
|
||||
String escape = HtmlUtil.escape(html);
|
||||
final String html = "<html><body>123'123'</body></html>";
|
||||
final String escape = HtmlUtil.escape(html);
|
||||
Assert.assertEquals("<html><body>123'123'</body></html>", escape);
|
||||
String restoreEscaped = HtmlUtil.unescape(escape);
|
||||
final String restoreEscaped = HtmlUtil.unescape(escape);
|
||||
Assert.assertEquals(html, restoreEscaped);
|
||||
Assert.assertEquals("'", HtmlUtil.unescape("'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest() {
|
||||
String html = "<alert></alert>";
|
||||
String filter = HtmlUtil.filter(html);
|
||||
final String html = "<alert></alert>";
|
||||
final String filter = HtmlUtil.filter(html);
|
||||
Assert.assertEquals("", filter);
|
||||
}
|
||||
|
||||
@@ -167,8 +167,8 @@ public class HtmlUtilTest {
|
||||
|
||||
@Test
|
||||
public void removeAllHtmlAttrTest() {
|
||||
String html = "<div class=\"test_div\" width=\"120\"></div>";
|
||||
String result = HtmlUtil.removeAllHtmlAttr(html, "div");
|
||||
final String html = "<div class=\"test_div\" width=\"120\"></div>";
|
||||
final String result = HtmlUtil.removeAllHtmlAttr(html, "div");
|
||||
Assert.assertEquals("<div></div>", result);
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class HttpRequestTest {
|
||||
@Ignore
|
||||
public void getCookiesTest() {
|
||||
// 检查在Connection关闭情况下Cookie是否可以正常获取
|
||||
HttpResponse res = HttpRequest.get("https://www.oschina.net/").execute();
|
||||
String body = res.body();
|
||||
final HttpResponse res = HttpRequest.get("https://www.oschina.net/").execute();
|
||||
final String body = res.body();
|
||||
Console.log(res.getCookies());
|
||||
Console.log(body);
|
||||
}
|
||||
@@ -50,17 +50,17 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void asyncHeadTest() {
|
||||
HttpResponse response = HttpRequest.head(url).execute();
|
||||
Map<String, List<String>> headers = response.headers();
|
||||
final HttpResponse response = HttpRequest.head(url).execute();
|
||||
final Map<String, List<String>> headers = response.headers();
|
||||
Console.log(headers);
|
||||
Console.log(response.body());
|
||||
}
|
||||
@@ -68,24 +68,24 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void asyncGetTest() {
|
||||
TimeInterval timer = DateUtil.timer();
|
||||
HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
|
||||
long interval = timer.interval();
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
|
||||
final long interval = timer.interval();
|
||||
timer.restart();
|
||||
Console.log(body.body());
|
||||
long interval2 = timer.interval();
|
||||
final long interval2 = timer.interval();
|
||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void syncGetTest() {
|
||||
TimeInterval timer = DateUtil.timer();
|
||||
HttpResponse body = HttpRequest.get(url).charset("GBK").execute();
|
||||
long interval = timer.interval();
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final HttpResponse body = HttpRequest.get(url).charset("GBK").execute();
|
||||
final long interval = timer.interval();
|
||||
timer.restart();
|
||||
Console.log(body.body());
|
||||
long interval2 = timer.interval();
|
||||
final long interval2 = timer.interval();
|
||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class HttpRequestTest {
|
||||
@Ignore
|
||||
public void customGetTest() {
|
||||
// 自定义构建HTTP GET请求,发送Http GET请求,针对HTTPS安全加密,可以自定义SSL
|
||||
HttpRequest request = HttpRequest.get(url)
|
||||
final HttpRequest request = HttpRequest.get(url)
|
||||
// 自定义返回编码
|
||||
.charset(CharsetUtil.GBK)
|
||||
// 禁用缓存
|
||||
@@ -106,7 +106,7 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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();
|
||||
Console.log(res);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getLocalTest() {
|
||||
List<String> list = new ArrayList<>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
list.add("hhhhh");
|
||||
list.add("sssss");
|
||||
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
final Map<String, Object> map = new HashMap<>(16);
|
||||
map.put("recordId", "12321321");
|
||||
map.put("page", "1");
|
||||
map.put("size", "2");
|
||||
@@ -143,10 +143,10 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithoutEncodeTest() {
|
||||
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 String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
||||
final HttpRequest get = HttpUtil.createGet(url);
|
||||
Console.log(get.getUrl());
|
||||
HttpResponse execute = get.execute();
|
||||
final HttpResponse execute = get.execute();
|
||||
Console.log(execute.body());
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class HttpRequestTest {
|
||||
// 从5.7.19开始关闭JDK的自动重定向功能,改为手动重定向
|
||||
// 当有多层重定向时,JDK的重定向会失效,或者说只有最后一个重定向有效,因此改为手动更易控制次数
|
||||
// 此链接有两次重定向,当设置次数为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";
|
||||
|
||||
// 方式1:全局设置
|
||||
@@ -188,20 +188,20 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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<>();
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void urlWithParamIfGetTest(){
|
||||
UrlBuilder urlBuilder = new UrlBuilder();
|
||||
final UrlBuilder urlBuilder = new UrlBuilder();
|
||||
urlBuilder.setScheme("https").setHost("hutool.cn");
|
||||
|
||||
HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||
final HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||
httpRequest.setMethod(Method.GET).execute();
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void postTest() {
|
||||
String result = HttpUtil.createPost("api.uhaozu.com/goods/description/1120448506")
|
||||
final String result = HttpUtil.createPost("api.uhaozu.com/goods/description/1120448506")
|
||||
.charset(CharsetUtil.NAME_UTF_8)
|
||||
.execute().body();
|
||||
Console.log(result);
|
||||
@@ -29,7 +29,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void postTest2() {
|
||||
// 某些接口对Accept头有特殊要求,此处自定义头
|
||||
String result = HttpUtil
|
||||
final String result = HttpUtil
|
||||
.createPost("http://cmp.ishanghome.com/cmp/v1/community/queryClusterCommunity")
|
||||
.header(Header.ACCEPT, "*/*")
|
||||
.execute()
|
||||
@@ -40,7 +40,7 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getTest() {
|
||||
String result1 = HttpUtil.get("http://photo.qzone.qq.com/fcgi-bin/fcg_list_album?uin=88888&outstyle=2", CharsetUtil.GBK);
|
||||
final String result1 = HttpUtil.get("http://photo.qzone.qq.com/fcgi-bin/fcg_list_album?uin=88888&outstyle=2", CharsetUtil.GBK);
|
||||
Console.log(result1);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class HttpUtilTest {
|
||||
public void getTest2() {
|
||||
// 此链接较为特殊,User-Agent去掉后进入一个JS跳转页面,如果设置了,需要开启302跳转
|
||||
// 自定义的默认header无效
|
||||
String result = HttpRequest
|
||||
final String result = HttpRequest
|
||||
.get("https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101457313&redirect_uri=http%3A%2F%2Fwww.benmovip.com%2Fpay-cloud%2Fqqlogin%2FgetCode&state=ok")
|
||||
.removeHeader(Header.USER_AGENT).execute().body();
|
||||
Console.log(result);
|
||||
@@ -59,7 +59,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void getTest3() {
|
||||
// 测试url中带有空格的情况
|
||||
String result1 = HttpUtil.get("http://hutool.cn:5000/kf?abc= d");
|
||||
final String result1 = HttpUtil.get("http://hutool.cn:5000/kf?abc= d");
|
||||
Console.log(result1);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void getTest4() {
|
||||
// 测试url中带有空格的情况
|
||||
byte[] str = HttpRequest.get("http://img01.fs.yiban.cn/mobile/2D0Y71").execute().bodyBytes();
|
||||
final byte[] str = HttpRequest.get("http://img01.fs.yiban.cn/mobile/2D0Y71").execute().bodyBytes();
|
||||
|
||||
FileUtil.writeBytes(str, "f:/test/2D.jpg");
|
||||
Console.log(str);
|
||||
@@ -77,7 +77,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void getTest5() {
|
||||
String url2 = "http://storage.chancecloud.com.cn/20200413_%E7%B2%A4B12313_386.pdf";
|
||||
ByteArrayOutputStream os2 = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream os2 = new ByteArrayOutputStream();
|
||||
HttpUtil.download(url2, os2, false);
|
||||
|
||||
url2 = "http://storage.chancecloud.com.cn/20200413_粤B12313_386.pdf";
|
||||
@@ -95,9 +95,9 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void downloadStringTest() {
|
||||
String url = "https://www.baidu.com";
|
||||
final String url = "https://www.baidu.com";
|
||||
// 从远程直接读取字符串,需要自定义编码,直接调用JDK方法
|
||||
String content2 = HttpUtil.downloadString(url, CharsetUtil.NAME_UTF_8);
|
||||
final String content2 = HttpUtil.downloadString(url, CharsetUtil.NAME_UTF_8);
|
||||
Console.log(content2);
|
||||
}
|
||||
|
||||
@@ -107,8 +107,8 @@ public class HttpUtilTest {
|
||||
// 请求列表页
|
||||
String listContent = HttpUtil.get("https://www.oschina.net/action/ajax/get_more_news_list?newsType=&p=2");
|
||||
// 使用正则获取所有标题
|
||||
List<String> titles = ReUtil.findAll("<span class=\"text-ellipsis\">(.*?)</span>", listContent, 1);
|
||||
for (String title : titles) {
|
||||
final List<String> titles = ReUtil.findAll("<span class=\"text-ellipsis\">(.*?)</span>", listContent, 1);
|
||||
for (final String title : titles) {
|
||||
// 打印标题
|
||||
Console.log(title);
|
||||
}
|
||||
@@ -120,8 +120,8 @@ public class HttpUtilTest {
|
||||
|
||||
@Test
|
||||
public void decodeParamsTest() {
|
||||
String paramsStr = "uuuu=0&a=b&c=%3F%23%40!%24%25%5E%26%3Ddsssss555555";
|
||||
Map<String, List<String>> map = HttpUtil.decodeParams(paramsStr, CharsetUtil.NAME_UTF_8);
|
||||
final String paramsStr = "uuuu=0&a=b&c=%3F%23%40!%24%25%5E%26%3Ddsssss555555";
|
||||
final Map<String, List<String>> map = HttpUtil.decodeParams(paramsStr, CharsetUtil.NAME_UTF_8);
|
||||
Assert.assertEquals("0", map.get("uuuu").get(0));
|
||||
Assert.assertEquals("b", map.get("a").get(0));
|
||||
Assert.assertEquals("?#@!$%^&=dsssss555555", map.get("c").get(0));
|
||||
@@ -130,17 +130,17 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
public void decodeParamMapTest() {
|
||||
// 参数值存在分界标记等号时
|
||||
Map<String, String> paramMap = HttpUtil.decodeParamMap("https://www.xxx.com/api.action?aa=123&f_token=NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=", CharsetUtil.UTF_8);
|
||||
final Map<String, String> paramMap = HttpUtil.decodeParamMap("https://www.xxx.com/api.action?aa=123&f_token=NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("123",paramMap.get("aa"));
|
||||
Assert.assertEquals("NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=",paramMap.get("f_token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toParamsTest() {
|
||||
String paramsStr = "uuuu=0&a=b&c=3Ddsssss555555";
|
||||
Map<String, List<String>> map = HttpUtil.decodeParams(paramsStr, CharsetUtil.NAME_UTF_8);
|
||||
final String paramsStr = "uuuu=0&a=b&c=3Ddsssss555555";
|
||||
final Map<String, List<String>> map = HttpUtil.decodeParams(paramsStr, CharsetUtil.NAME_UTF_8);
|
||||
|
||||
String encodedParams = HttpUtil.toParams(map);
|
||||
final String encodedParams = HttpUtil.toParams(map);
|
||||
Assert.assertEquals(paramsStr, encodedParams);
|
||||
}
|
||||
|
||||
@@ -253,13 +253,13 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void patchTest() {
|
||||
// 验证patch请求是否可用
|
||||
String body = HttpRequest.patch("https://www.baidu.com").execute().body();
|
||||
final String body = HttpRequest.patch("https://www.baidu.com").execute().body();
|
||||
Console.log(body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithFormTest() {
|
||||
Map<String, Object> param = new LinkedHashMap<>();
|
||||
final Map<String, Object> param = new LinkedHashMap<>();
|
||||
param.put("AccessKeyId", "123");
|
||||
param.put("Action", "DescribeDomainRecords");
|
||||
param.put("Format", "date");
|
||||
@@ -298,19 +298,19 @@ public class HttpUtilTest {
|
||||
|
||||
@Test
|
||||
public void normalizeParamsTest() {
|
||||
String encodeResult = HttpUtil.normalizeParams("参数", CharsetUtil.UTF_8);
|
||||
final String encodeResult = HttpUtil.normalizeParams("参数", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("%E5%8F%82%E6%95%B0", encodeResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeBlankParamsTest() {
|
||||
String encodeResult = HttpUtil.normalizeParams("", CharsetUtil.UTF_8);
|
||||
final String encodeResult = HttpUtil.normalizeParams("", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("", encodeResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMimeTypeTest() {
|
||||
String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
||||
final String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
||||
Assert.assertNull(mimeType);
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void getWeixinTest(){
|
||||
// 测试特殊URL,即URL中有&情况是否请求正常
|
||||
String url = "https://mp.weixin.qq.com/s?__biz=MzI5NjkyNTIxMg==&mid=100000465&idx=1&sn=1044c0d19723f74f04f4c1da34eefa35&chksm=6cbda3a25bca2ab4516410db6ce6e125badaac2f8c5548ea6e18eab6dc3c5422cb8cbe1095f7";
|
||||
final String url = "https://mp.weixin.qq.com/s?__biz=MzI5NjkyNTIxMg==&mid=100000465&idx=1&sn=1044c0d19723f74f04f4c1da34eefa35&chksm=6cbda3a25bca2ab4516410db6ce6e125badaac2f8c5548ea6e18eab6dc3c5422cb8cbe1095f7";
|
||||
final String s = HttpUtil.get(url);
|
||||
Console.log(s);
|
||||
}
|
||||
@@ -326,7 +326,7 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getNocovTest(){
|
||||
String url = "https://qiniu.nocov.cn/medical-manage%2Ftest%2FBANNER_IMG%2F444004467954556928%2F1595215173047icon.png~imgReduce?e=1597081986&token=V2lJYVgQgAv_sbypfEZ0qpKs6TzD1q5JIDVr0Tw8:89cbBkLLwEc9JsMoCLkAEOu820E=";
|
||||
final String url = "https://qiniu.nocov.cn/medical-manage%2Ftest%2FBANNER_IMG%2F444004467954556928%2F1595215173047icon.png~imgReduce?e=1597081986&token=V2lJYVgQgAv_sbypfEZ0qpKs6TzD1q5JIDVr0Tw8:89cbBkLLwEc9JsMoCLkAEOu820E=";
|
||||
final String s = HttpUtil.get(url);
|
||||
Console.log(s);
|
||||
}
|
||||
@@ -341,7 +341,7 @@ public class HttpUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void gimg2Test(){
|
||||
byte[] bytes = HttpUtil.downloadBytes("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0H320120Z3%2F200H3120Z3-6-1200.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621996490&t=8c384c2823ea453da15a1b9cd5183eea");
|
||||
final byte[] bytes = HttpUtil.downloadBytes("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0H320120Z3%2F200H3120Z3-6-1200.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621996490&t=8c384c2823ea453da15a1b9cd5183eea");
|
||||
Console.log(Base64.encode(bytes));
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class HttpUtilTest {
|
||||
@Ignore
|
||||
public void getPicTest(){
|
||||
HttpGlobalConfig.setDecodeUrl(false);
|
||||
String url = "https://p3-sign.douyinpic.com/tos-cn-i-0813/f41afb2e79a94dcf80970affb9a69415~noop.webp?x-expires=1647738000&x-signature=%2Br1ekUCGjXiu50Y%2Bk0MO4ovulK8%3D&from=4257465056&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sh=&sc=&l=2022021809224601020810013524310DD3&biz_tag=aweme_images";
|
||||
final String url = "https://p3-sign.douyinpic.com/tos-cn-i-0813/f41afb2e79a94dcf80970affb9a69415~noop.webp?x-expires=1647738000&x-signature=%2Br1ekUCGjXiu50Y%2Bk0MO4ovulK8%3D&from=4257465056&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sh=&sc=&l=2022021809224601020810013524310DD3&biz_tag=aweme_images";
|
||||
|
||||
final HttpRequest request = HttpRequest.of(url).method(Method.GET);
|
||||
Console.log(request.execute().body());
|
||||
|
@@ -16,7 +16,7 @@ public class RestTest {
|
||||
|
||||
@Test
|
||||
public void contentTypeTest() {
|
||||
HttpRequest request = HttpRequest.post("http://localhost:8090/rest/restTest/")//
|
||||
final HttpRequest request = HttpRequest.post("http://localhost:8090/rest/restTest/")//
|
||||
.body(JSONUtil.createObj()
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
@@ -26,7 +26,7 @@ public class RestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void postTest() {
|
||||
HttpRequest request = HttpRequest.post("http://localhost:8090/rest/restTest/")//
|
||||
final HttpRequest request = HttpRequest.post("http://localhost:8090/rest/restTest/")//
|
||||
.body(JSONUtil.createObj()
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
@@ -36,7 +36,7 @@ public class RestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void postTest2() {
|
||||
String result = HttpUtil.post("http://localhost:8090/rest/restTest/", JSONUtil.createObj()//
|
||||
final String result = HttpUtil.post("http://localhost:8090/rest/restTest/", JSONUtil.createObj()//
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
Console.log(result);
|
||||
@@ -45,7 +45,7 @@ public class RestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithBodyTest() {
|
||||
HttpRequest request = HttpRequest.get("http://localhost:8888/restTest")//
|
||||
final HttpRequest request = HttpRequest.get("http://localhost:8888/restTest")//
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(JSONUtil.createObj()
|
||||
.set("aaa", "aaaValue")
|
||||
@@ -56,7 +56,7 @@ public class RestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithBodyTest2() {
|
||||
HttpRequest request = HttpRequest.get("https://ad.oceanengine.com/open_api/2/advertiser/info/")//
|
||||
final HttpRequest request = HttpRequest.get("https://ad.oceanengine.com/open_api/2/advertiser/info/")//
|
||||
// Charles代理
|
||||
.setHttpProxy("localhost", 8888)
|
||||
.header("Access-Token","")
|
||||
|
@@ -24,28 +24,28 @@ public class UploadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadFilesTest() {
|
||||
File file = FileUtil.file("d:\\图片1.JPG");
|
||||
File file2 = FileUtil.file("d:\\图片3.png");
|
||||
final File file = FileUtil.file("d:\\图片1.JPG");
|
||||
final File file2 = FileUtil.file("d:\\图片3.png");
|
||||
|
||||
// 方法一:自定义构建表单
|
||||
HttpRequest request = HttpRequest//
|
||||
final HttpRequest request = HttpRequest//
|
||||
.post("http://localhost:8888/file")//
|
||||
.form("file", file2, file)//
|
||||
.form("fileType", "图片");
|
||||
HttpResponse response = request.execute();
|
||||
final HttpResponse response = request.execute();
|
||||
Console.log(response.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadFileTest() {
|
||||
File file = FileUtil.file("D:\\face.jpg");
|
||||
final File file = FileUtil.file("D:\\face.jpg");
|
||||
|
||||
// 方法二:使用统一的表单,Http模块会自动识别参数类型,并完成上传
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
final HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("city", "北京");
|
||||
paramMap.put("file", file);
|
||||
String result = HttpUtil.post("http://wthrcdn.etouch.cn/weather_mini", paramMap);
|
||||
final String result = HttpUtil.post("http://wthrcdn.etouch.cn/weather_mini", paramMap);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@@ -53,19 +53,19 @@ public class UploadTest {
|
||||
@Ignore
|
||||
public void uploadTest2() {
|
||||
//客户端
|
||||
String url = "http://192.168.1.200:8888/meta/upload/img";
|
||||
Path file = Paths.get("D:\\test\\testBigData_upload.xlsx");
|
||||
Map<String, String> headers = new HashMap<>(16);
|
||||
final String url = "http://192.168.1.200:8888/meta/upload/img";
|
||||
final Path file = Paths.get("D:\\test\\testBigData_upload.xlsx");
|
||||
final Map<String, String> headers = new HashMap<>(16);
|
||||
headers.put("md5", "aaaaaaaa");
|
||||
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
final Map<String, Object> params = new HashMap<>(16);
|
||||
params.put("fileName", file.toFile().getName());
|
||||
params.put("file", file.toFile());
|
||||
HttpRequest httpRequest = HttpRequest.post(url)
|
||||
final HttpRequest httpRequest = HttpRequest.post(url)
|
||||
.setChunkedStreamingMode(1024 * 1024)
|
||||
.headerMap(headers, false)
|
||||
.form(params);
|
||||
HttpResponse httpResponse = httpRequest.execute();
|
||||
final HttpResponse httpResponse = httpRequest.execute();
|
||||
Console.log(httpResponse);
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ public class UploadTest {
|
||||
public void smmsTest(){
|
||||
// https://github.com/dromara/hutool/issues/2079
|
||||
// hutool的user agent 被封了
|
||||
String token = "test";
|
||||
String url = "https://sm.ms/api/v2/upload";
|
||||
String result = HttpUtil.createPost(url)
|
||||
final String token = "test";
|
||||
final String url = "https://sm.ms/api/v2/upload";
|
||||
final String result = HttpUtil.createPost(url)
|
||||
.header(Header.USER_AGENT, "PostmanRuntime/7.28.4")
|
||||
.auth(token)
|
||||
.form("smfile", FileUtil.file("d:/test/qrcodeCustom.png"))
|
||||
|
@@ -13,7 +13,7 @@ public class MultipartBodyTest {
|
||||
|
||||
@Test
|
||||
public void buildTest(){
|
||||
Map<String, Object> form = new HashMap<>();
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
form.put("pic1", "pic1 content");
|
||||
form.put("pic2", new HttpResource(
|
||||
new StringResource("pic2 content"), "text/plain"));
|
||||
|
@@ -4,7 +4,7 @@ import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
public class BlankServerTest {
|
||||
public static void main(String[] args) {
|
||||
public static void main(final String[] args) {
|
||||
HttpUtil.createServer(8888)
|
||||
.addAction("/", (req, res)-> res.write("Hello Hutool Server", ContentType.JSON.getValue()))
|
||||
.start();
|
||||
|
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpUtil;
|
||||
|
||||
public class DocServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(final String[] args) {
|
||||
HttpUtil.createServer(80)
|
||||
// 设置默认根目录,
|
||||
.setRoot("D:\\workspace\\site\\hutool-site")
|
||||
|
@@ -9,7 +9,7 @@ import cn.hutool.json.JSONUtil;
|
||||
|
||||
public class SimpleServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(final String[] args) {
|
||||
HttpUtil.createServer(8888)
|
||||
.addFilter(((req, res, chain) -> {
|
||||
Console.log("Filter: " + req.getPath());
|
||||
@@ -23,7 +23,7 @@ public class SimpleServerTest {
|
||||
)
|
||||
// 返回JSON数据测试
|
||||
.addAction("/restTest", (request, response) -> {
|
||||
String res = JSONUtil.createObj()
|
||||
final String res = JSONUtil.createObj()
|
||||
.set("id", 1)
|
||||
.set("method", request.getMethod())
|
||||
.set("request", request.getBody())
|
||||
@@ -43,7 +43,7 @@ public class SimpleServerTest {
|
||||
Console.log(request.getParams());
|
||||
final UploadFile[] files = request.getMultipart().getFiles("file");
|
||||
// 传入目录,默认读取HTTP头中的文件名然后创建文件
|
||||
for (UploadFile file : files) {
|
||||
for (final UploadFile file : files) {
|
||||
file.write("d:/test/");
|
||||
Console.log("Write file: d:/test/" + file.getFileName());
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseDesktopTest() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1";
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1";
|
||||
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Chrome", ua.getBrowser().toString());
|
||||
Assert.assertEquals("14.0.835.163", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -22,9 +22,9 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseMobileTest() {
|
||||
String uaStr = "User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
|
||||
final String uaStr = "User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
|
||||
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Safari", ua.getBrowser().toString());
|
||||
Assert.assertEquals("5.0.2", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -37,8 +37,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseMiui10WithChromeTest() {
|
||||
String uaStr = "Mozilla/5.0 (Linux; Android 9; MIX 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Mobile Safari/537.36";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Linux; Android 9; MIX 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Mobile Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Chrome", ua.getBrowser().toString());
|
||||
Assert.assertEquals("70.0.3538.80", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -51,8 +51,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseHuaweiPhoneWithNativeBrowserTest() {
|
||||
String uaString = "Mozilla/5.0 (Linux; Android 10; EML-AL00 Build/HUAWEIEML-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Linux; Android 10; EML-AL00 Build/HUAWEIEML-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("Android Browser", ua.getBrowser().toString());
|
||||
Assert.assertEquals("4.0", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -65,8 +65,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseSamsungPhoneWithNativeBrowserTest() {
|
||||
String uaString = "Dalvik/2.1.0 (Linux; U; Android 9; SM-G950U Build/PPR1.180610.011)";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Dalvik/2.1.0 (Linux; U; Android 9; SM-G950U Build/PPR1.180610.011)";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("Android Browser", ua.getBrowser().toString());
|
||||
Assert.assertNull(ua.getVersion());
|
||||
Assert.assertEquals("Unknown", ua.getEngine().toString());
|
||||
@@ -79,8 +79,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWindows10WithChromeTest() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Chrome", ua.getBrowser().toString());
|
||||
Assert.assertEquals("70.0.3538.102", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -93,8 +93,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWindows10WithIe11Test() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSIE11", ua.getBrowser().toString());
|
||||
Assert.assertEquals("11.0", ua.getVersion());
|
||||
Assert.assertEquals("Trident", ua.getEngine().toString());
|
||||
@@ -107,8 +107,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWindows10WithIeMobileLumia520Test() {
|
||||
String uaStr = "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 ";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 ";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("IEMobile", ua.getBrowser().toString());
|
||||
Assert.assertEquals("11.0", ua.getVersion());
|
||||
Assert.assertEquals("Trident", ua.getEngine().toString());
|
||||
@@ -121,8 +121,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWindows10WithIe8EmulatorTest() {
|
||||
String uaStr = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSIE", ua.getBrowser().toString());
|
||||
Assert.assertEquals("8.0", ua.getVersion());
|
||||
Assert.assertEquals("Trident", ua.getEngine().toString());
|
||||
@@ -135,8 +135,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWindows10WithEdgeTest() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSEdge", ua.getBrowser().toString());
|
||||
Assert.assertEquals("18.17763", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -149,8 +149,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseEdgeOnLumia950XLTest() {
|
||||
String uaStr = "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36 Edge/15.14900";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36 Edge/15.14900";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSEdge", ua.getBrowser().toString());
|
||||
Assert.assertEquals("15.14900", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -163,8 +163,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseChromeOnWindowsServer2012R2Test() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Chrome", ua.getBrowser().toString());
|
||||
Assert.assertEquals("63.0.3239.132", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -177,8 +177,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseIE11OnWindowsServer2008R2Test() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSIE11", ua.getBrowser().toString());
|
||||
Assert.assertEquals("11.0", ua.getVersion());
|
||||
Assert.assertEquals("Trident", ua.getEngine().toString());
|
||||
@@ -191,8 +191,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseEdgeTest() {
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.69 Safari/537.36 Edg/81.0.416.34";
|
||||
UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.69 Safari/537.36 Edg/81.0.416.34";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSEdge", ua.getBrowser().toString());
|
||||
Assert.assertEquals("81.0.416.34", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -208,8 +208,8 @@ public class UserAgentUtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void parseMicroMessengerTest() {
|
||||
String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A372 MicroMessenger/7.0.17(0x17001127) NetType/WIFI Language/zh_CN";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A372 MicroMessenger/7.0.17(0x17001127) NetType/WIFI Language/zh_CN";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("MicroMessenger", ua.getBrowser().toString());
|
||||
Assert.assertEquals("7.0.17", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -222,8 +222,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWorkWxTest() {
|
||||
String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wxwork/3.0.31 MicroMessenger/7.0.1 Language/zh";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wxwork/3.0.31 MicroMessenger/7.0.1 Language/zh";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("wxwork", ua.getBrowser().toString());
|
||||
Assert.assertEquals("3.0.31", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -235,8 +235,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseQQTest() {
|
||||
String uaString = "User-Agent: MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "User-Agent: MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("QQBrowser", ua.getBrowser().toString());
|
||||
Assert.assertEquals("26", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -249,8 +249,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseDingTalkTest() {
|
||||
String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/18A373 AliApp(DingTalk/5.1.33) com.laiwang.DingTalk/13976299 Channel/201200 language/zh-Hans-CN WK";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/18A373 AliApp(DingTalk/5.1.33) com.laiwang.DingTalk/13976299 Channel/201200 language/zh-Hans-CN WK";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("DingTalk", ua.getBrowser().toString());
|
||||
Assert.assertEquals("5.1.33", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -263,8 +263,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseAlipayTest() {
|
||||
String uaString = "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; FRD-AL00 Build/HUAWEIFRD-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.3.8.909 UWS/2.10.2.5 Mobile Safari/537.36 UCBS/2.10.2.5 Nebula AlipayDefined(nt:WIFI,ws:360|0|3.0) AliApp(AP/10.0.18.062203) AlipayClient/10.0.18.062203 Language/zh-Hans useStatusBar/true";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; FRD-AL00 Build/HUAWEIFRD-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.3.8.909 UWS/2.10.2.5 Mobile Safari/537.36 UCBS/2.10.2.5 Nebula AlipayDefined(nt:WIFI,ws:360|0|3.0) AliApp(AP/10.0.18.062203) AlipayClient/10.0.18.062203 Language/zh-Hans useStatusBar/true";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("Alipay", ua.getBrowser().toString());
|
||||
Assert.assertEquals("10.0.18.062203", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -277,8 +277,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseTaobaoTest() {
|
||||
String uaString = "Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 2C Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 AliApp(TB/4.9.2) WindVane/5.2.2 TBANDROID/700342@taobao_android_4.9.2 720X1280";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 2C Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 AliApp(TB/4.9.2) WindVane/5.2.2 TBANDROID/700342@taobao_android_4.9.2 720X1280";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("Taobao", ua.getBrowser().toString());
|
||||
Assert.assertEquals("4.9.2", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -291,8 +291,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseUCTest() {
|
||||
String uaString = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("UCBrowser", ua.getBrowser().toString());
|
||||
Assert.assertEquals("4.0.3214.0", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -305,8 +305,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseUCTest2() {
|
||||
String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/16G102 UCBrowser/12.7.6.1251 Mobile AliApp(TUnionSDK/0.1.20.3)";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/16G102 UCBrowser/12.7.6.1251 Mobile AliApp(TUnionSDK/0.1.20.3)";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("UCBrowser", ua.getBrowser().toString());
|
||||
Assert.assertEquals("12.7.6.1251", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -319,8 +319,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseQuarkTest() {
|
||||
String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-cn) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/16G102 Quark/3.6.2.993 Mobile";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-cn) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/16G102 Quark/3.6.2.993 Mobile";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("Quark", ua.getBrowser().toString());
|
||||
Assert.assertEquals("3.6.2.993", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -333,8 +333,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWxworkTest() {
|
||||
String uaString = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1326.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 wxwork/3.1.10 (MicroMessenger/6.2) WindowsWechat";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1326.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 wxwork/3.1.10 (MicroMessenger/6.2) WindowsWechat";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("wxwork", ua.getBrowser().toString());
|
||||
Assert.assertEquals("3.1.10", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -347,8 +347,8 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseWxworkMobileTest() {
|
||||
String uaString = "Mozilla/5.0 (Linux; Android 10; JSN-AL00 Build/HONORJSN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045710 Mobile Safari/537.36 wxwork/3.1.10 ColorScheme/Light MicroMessenger/7.0.1 NetType/WIFI Language/zh Lang/zh";
|
||||
UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
final String uaString = "Mozilla/5.0 (Linux; Android 10; JSN-AL00 Build/HONORJSN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045710 Mobile Safari/537.36 wxwork/3.1.10 ColorScheme/Light MicroMessenger/7.0.1 NetType/WIFI Language/zh Lang/zh";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaString);
|
||||
Assert.assertEquals("wxwork", ua.getBrowser().toString());
|
||||
Assert.assertEquals("3.1.10", ua.getVersion());
|
||||
Assert.assertEquals("Webkit", ua.getEngine().toString());
|
||||
@@ -362,7 +362,7 @@ public class UserAgentUtilTest {
|
||||
@Test
|
||||
public void parseEdgATest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I4MCBP
|
||||
String uaStr = "userAgent: Mozilla/5.0 (Linux; Android 11; MI 9 Transparent Edition) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Mobile Safari/537.36 EdgA/96.0.1054.36";
|
||||
final String uaStr = "userAgent: Mozilla/5.0 (Linux; Android 11; MI 9 Transparent Edition) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Mobile Safari/537.36 EdgA/96.0.1054.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("MSEdge", ua.getBrowser().toString());
|
||||
Assert.assertEquals("96.0.1054.36", ua.getVersion());
|
||||
@@ -377,7 +377,7 @@ public class UserAgentUtilTest {
|
||||
@Test
|
||||
public void parseLenovoTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I4QBMD
|
||||
String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30";
|
||||
final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
|
||||
Assert.assertEquals("Lenovo", ua.getBrowser().toString());
|
||||
@@ -392,7 +392,7 @@ public class UserAgentUtilTest {
|
||||
|
||||
@Test
|
||||
public void parseXiaoMiTest(){
|
||||
String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/89.0.4389.116 Safari/534.24 XiaoMi/MiuiBrowser/16.0.18 swan-mibrowser";
|
||||
final String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/89.0.4389.116 Safari/534.24 XiaoMi/MiuiBrowser/16.0.18 swan-mibrowser";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
|
||||
Assert.assertEquals("MiuiBrowser", ua.getBrowser().toString());
|
||||
@@ -408,7 +408,7 @@ public class UserAgentUtilTest {
|
||||
@Test
|
||||
public void parseFromDeepinTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I50YGY
|
||||
String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
|
||||
final String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
Assert.assertEquals("Linux", ua.getOs().toString());
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public class SoapClientTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void requestTest() {
|
||||
SoapClient client = SoapClient.create("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx")
|
||||
final SoapClient client = SoapClient.create("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx")
|
||||
.setMethod("web:getCountryCityByIp", "http://WebXml.com.cn/")
|
||||
.setCharset(CharsetUtil.GBK)
|
||||
.setParam("theIpAddress", "218.21.240.106");
|
||||
@@ -32,11 +32,11 @@ public class SoapClientTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void requestForMessageTest() throws SOAPException {
|
||||
SoapClient client = SoapClient.create("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx")
|
||||
final SoapClient client = SoapClient.create("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx")
|
||||
.setMethod("web:getCountryCityByIp", "http://WebXml.com.cn/")
|
||||
.setParam("theIpAddress", "218.21.240.106");
|
||||
|
||||
SOAPMessage message = client.sendForMessage();
|
||||
final SOAPMessage message = client.sendForMessage();
|
||||
Console.log(message.getSOAPBody().getTextContent());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user