use of cn.hutool.core.net.url.UrlBuilder in project hutool by dromara.
the class UrlBuilderTest method ofSpecialTest.
@Test
public void ofSpecialTest() {
// 测试不规范的或者无需解码的字符串是否成功解码
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals("http", builder.getScheme());
Assert.assertEquals("www.hutool.cn", builder.getHost());
Assert.assertEquals("aaa", builder.getPath().getSegment(0));
Assert.assertEquals("bbb", builder.getPath().getSegment(1));
Assert.assertEquals("张三", builder.getQuery().get("a"));
Assert.assertEquals("%四", builder.getQuery().get("b"));
Assert.assertEquals("frag1", builder.getFragment());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by dromara.
the class UrlBuilderTest method endWithSlashTest.
@Test
public void endWithSlashTest() {
// 原URL中以/结尾,则这个规则需保留,issue#I1G44J@Gitee
final String today = DateUtil.date().toString("yyyyMMdd");
final String getWorkDayUrl = "https://tool.bitefu.net/jiari/?info=1&d=" + today;
final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals(getWorkDayUrl, builder.toString());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method endWithSlashTest.
@Test
public void endWithSlashTest() {
// 原URL中以/结尾,则这个规则需保留,issue#I1G44J@Gitee
final String today = DateUtil.date().toString("yyyyMMdd");
final String getWorkDayUrl = "https://tool.bitefu.net/jiari/?info=1&d=" + today;
final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.CHARSET_UTF_8);
Assert.assertEquals(getWorkDayUrl, builder.toString());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method testEncodeInQuery.
@Test
public void testEncodeInQuery() {
// b=4?6 参数中有未编码的?
String webUrl = "http://exmple.com/patha/pathb?a=123&b=4?6&c=789";
final UrlBuilder urlBuilder = UrlBuilder.of(webUrl, StandardCharsets.UTF_8);
Assert.assertEquals("a=123&b=4?6&c=789", urlBuilder.getQueryStr());
}
use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.
the class UrlBuilderTest method fragmentTest.
@Test
public void fragmentTest() {
// https://gitee.com/dromara/hutool/issues/I49KAL#note_8060874
String url = "https://www.hutool.cn/#/a/b?timestamp=1640391380204";
final UrlBuilder builder = UrlBuilder.ofHttp(url);
Assert.assertEquals(url, builder.toString());
}
Aggregations