Search in sources :

Example 11 with UrlBuilder

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

the class UrlBuilderTest method slashEncodeTest.

@Test
public void slashEncodeTest() {
    // https://github.com/dromara/hutool/issues/1904
    // 在query中,"/"是不可转义字符
    // 见:https://www.rfc-editor.org/rfc/rfc3986.html#section-3.4
    String url = "https://invoice.maycur.com/2b27a802-8423-4d41-86f5-63a6b259f61e.xlsx?download/2b27a802-8423-4d41-86f5-63a6b259f61e.xlsx&e=1630491088";
    final UrlBuilder urlBuilder = UrlBuilder.ofHttp(url);
    Assert.assertEquals(url, urlBuilder.toString());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 12 with UrlBuilder

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

the class UrlBuilderTest method paramTest.

@Test
public void paramTest() {
    String url = "http://ci.xiaohongshu.com/spectrum/c136c98aa2047babe25b994a26ffa7b492bd8058?imageMogr2/thumbnail/x800/format/jpg";
    final UrlBuilder builder = UrlBuilder.ofHttp(url);
    Assert.assertEquals(url, builder.toString());
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 13 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 14 with UrlBuilder

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

the class UrlQueryTest method ofHttpWithoutEncodeTest.

@Test
public void ofHttpWithoutEncodeTest() {
    // charset为null表示不做编码
    String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
    final UrlBuilder urlBuilder = UrlBuilder.ofHttpWithoutEncode(url);
    final String queryStr = urlBuilder.getQueryStr();
    Assert.assertEquals("imageMogr2/auto-orient/thumbnail/500&pid=259848", queryStr);
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Test(org.junit.Test)

Example 15 with UrlBuilder

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

the class HttpRequestTest method urlWithParamIfGetTest.

@Test
@Ignore
public void urlWithParamIfGetTest() {
    UrlBuilder urlBuilder = new UrlBuilder();
    urlBuilder.setScheme("https").setHost("hutool.cn");
    HttpRequest httpRequest = new HttpRequest(urlBuilder);
    httpRequest.setMethod(Method.GET).execute();
}
Also used : UrlBuilder(cn.hutool.core.net.url.UrlBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

UrlBuilder (cn.hutool.core.net.url.UrlBuilder)57 Test (org.junit.Test)54 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 Ignore (org.junit.Ignore)2 TableMap (cn.hutool.core.map.TableMap)1 AgentAuthorize (io.jpom.system.AgentAuthorize)1 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1