Search in sources :

Example 1 with UrlBuilder

use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.

the class UrlBuilderTest method fragmentAppendParamTest.

@Test
public void fragmentAppendParamTest() {
    // https://gitee.com/dromara/hutool/issues/I49KAL#note_8060874
    String url = "https://www.hutool.cn/#/a/b";
    final UrlBuilder builder = UrlBuilder.ofHttp(url);
    builder.setFragment(builder.getFragment() + "?timestamp=1640391380204");
    Assert.assertEquals("https://www.hutool.cn/#/a/b?timestamp=1640391380204", builder.toString());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 2 with UrlBuilder

use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.

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 3 with UrlBuilder

use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.

the class UrlBuilderTest method blankEncodeTest.

@Test
public void blankEncodeTest() {
    final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.CHARSET_UTF_8);
    Assert.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 4 with UrlBuilder

use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.

the class UrlBuilderTest method ofTest.

@Test
public void ofTest() {
    final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb/?a=1&b=2#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("1", builder.getQuery().get("a"));
    Assert.assertEquals("2", builder.getQuery().get("b"));
    Assert.assertEquals("frag1", builder.getFragment());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 5 with UrlBuilder

use of cn.hutool.core.net.url.UrlBuilder in project hutool by looly.

the class UrlBuilderTest method ofWithBlankTest.

@Test
public void ofWithBlankTest() {
    final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%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)

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