mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
1e46b4a0b3
commit
f76bb8c6c2
@ -30,6 +30,21 @@ public class MapBuilder<K, V> implements Builder<Map<K, V>> {
|
|||||||
|
|
||||||
private final Map<K, V> map;
|
private final Map<K, V> map;
|
||||||
|
|
||||||
|
// region ----- of
|
||||||
|
/**
|
||||||
|
* 创建Builder,默认HashMap实现
|
||||||
|
*
|
||||||
|
* @param <K> Key类型
|
||||||
|
* @param <V> Value类型
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @return MapBuilder
|
||||||
|
*/
|
||||||
|
public static <K, V> MapBuilder<K, V> of(final K key, final V value) {
|
||||||
|
final MapBuilder<K, V> builder = of();
|
||||||
|
return builder.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Builder,默认HashMap实现
|
* 创建Builder,默认HashMap实现
|
||||||
*
|
*
|
||||||
@ -67,6 +82,7 @@ public class MapBuilder<K, V> implements Builder<Map<K, V>> {
|
|||||||
public static <K, V> MapBuilder<K, V> of(final Map<K, V> map) {
|
public static <K, V> MapBuilder<K, V> of(final Map<K, V> map) {
|
||||||
return new MapBuilder<>(map);
|
return new MapBuilder<>(map);
|
||||||
}
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 链式Map创建类
|
* 链式Map创建类
|
||||||
|
@ -75,6 +75,19 @@ public final class UrlBuilder implements Builder<String> {
|
|||||||
*/
|
*/
|
||||||
private final boolean needEncodePercent;
|
private final boolean needEncodePercent;
|
||||||
|
|
||||||
|
// region ----- of
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用UrlBuilder构建UrlBuilder
|
||||||
|
*
|
||||||
|
* @param builder {@code UrlBuilder}
|
||||||
|
* @return UrlBuilder
|
||||||
|
*/
|
||||||
|
public static UrlBuilder of(final UrlBuilder builder) {
|
||||||
|
return of(builder.getScheme(), builder.getHost(), builder.getPort(), builder.getPathStr(),
|
||||||
|
builder.getQueryStr(), builder.getFragment(), builder.getCharset());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用URI构建UrlBuilder
|
* 使用URI构建UrlBuilder
|
||||||
*
|
*
|
||||||
@ -203,6 +216,7 @@ public final class UrlBuilder implements Builder<String> {
|
|||||||
public static UrlBuilder of() {
|
public static UrlBuilder of() {
|
||||||
return new UrlBuilder();
|
return new UrlBuilder();
|
||||||
}
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
|
@ -358,7 +358,7 @@ public class Request implements HeaderOperation<Request> {
|
|||||||
if (Method.GET.equals(method) && !this.isRest) {
|
if (Method.GET.equals(method) && !this.isRest) {
|
||||||
final HttpBody body = this.body;
|
final HttpBody body = this.body;
|
||||||
if (body instanceof FormBody) {
|
if (body instanceof FormBody) {
|
||||||
final UrlBuilder urlBuilder = UrlBuilder.of(this.url.toURL(), this.url.getCharset());
|
final UrlBuilder urlBuilder = UrlBuilder.of(this.url);
|
||||||
UrlQuery query = urlBuilder.getQuery();
|
UrlQuery query = urlBuilder.getQuery();
|
||||||
if (null == query) {
|
if (null == query) {
|
||||||
query = UrlQuery.of();
|
query = UrlQuery.of();
|
||||||
|
@ -12,28 +12,42 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.http;
|
package org.dromara.hutool.http;
|
||||||
|
|
||||||
import org.dromara.hutool.core.lang.Console;
|
|
||||||
import org.dromara.hutool.core.map.MapBuilder;
|
import org.dromara.hutool.core.map.MapBuilder;
|
||||||
import org.dromara.hutool.http.client.Request;
|
import org.dromara.hutool.http.client.Request;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import org.dromara.hutool.http.client.Response;
|
||||||
import org.dromara.hutool.http.client.engine.httpclient4.HttpClient4Engine;
|
import org.dromara.hutool.http.client.engine.ClientEngine;
|
||||||
|
import org.dromara.hutool.http.client.engine.okhttp.OkHttpEngine;
|
||||||
import org.dromara.hutool.http.meta.Method;
|
import org.dromara.hutool.http.meta.Method;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class IssueI85C9STest {
|
public class IssueI85C9STest {
|
||||||
|
|
||||||
|
private final ClientEngine engine = new OkHttpEngine();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
void getWithFormTest() {
|
void getWithFormTest() {
|
||||||
|
|
||||||
final Response send = Request.of("http://localhost:8888/formTest")
|
final Response send = Request.of("http://localhost:8888/formTest")
|
||||||
.method(Method.GET)
|
.method(Method.GET)
|
||||||
.form(MapBuilder.of(new HashMap<String, Object>()).put("a", 1).put("b", 2).build())
|
.setRest(true)
|
||||||
.send(new HttpClient4Engine());
|
.form(MapBuilder.of("a", (Object)1).put("b", 2).build())
|
||||||
|
.send(engine);
|
||||||
|
|
||||||
Console.log(send.bodyStr());
|
Assertions.assertEquals("{a=[1], b=[2]}", send.bodyStr());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void getWithFormAndUrlParamTest() {
|
||||||
|
|
||||||
|
final Response send = Request.of("http://localhost:8888/formTest?c=3")
|
||||||
|
.method(Method.GET)
|
||||||
|
.form(MapBuilder.of("a", (Object)1).put("b", 2).build())
|
||||||
|
.send(engine);
|
||||||
|
|
||||||
|
Assertions.assertEquals("{a=[1], b=[2], c=[3]}", send.bodyStr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user