Search in sources :

Example 21 with UrlBuilder

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());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 22 with UrlBuilder

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());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 23 with UrlBuilder

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());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 24 with UrlBuilder

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());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 25 with UrlBuilder

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());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Aggregations

UrlBuilder (cn.hutool.core.net.url.UrlBuilder)45 Test (org.junit.Test)44 URI (java.net.URI)2 AgentAuthorize (io.jpom.system.AgentAuthorize)1 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1