mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix comment
This commit is contained in:
parent
b048cc7fd7
commit
6dc8524e69
@ -3608,7 +3608,7 @@ public class CharSequenceUtil {
|
||||
* replaceFun可以通过{@link Matcher}提取出匹配到的内容的不同部分,然后经过重新处理、组装变成新的内容放回原位。
|
||||
*
|
||||
* <pre class="code">
|
||||
* replaceAll(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-")
|
||||
* replace(this.content, "(\\d+)", parameters -> "-" + parameters.group(1) + "-")
|
||||
* // 结果为:"ZZZaaabbbccc中文-1234-"
|
||||
* </pre>
|
||||
*
|
||||
|
@ -32,6 +32,7 @@ import java.net.URLStreamHandler;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* http请求类<br>
|
||||
@ -486,8 +487,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
return this.form(name, (File) value);
|
||||
}
|
||||
|
||||
if(value instanceof Resource){
|
||||
return form(name, (Resource)value);
|
||||
if (value instanceof Resource) {
|
||||
return form(name, (Resource) value);
|
||||
}
|
||||
|
||||
// 普通值
|
||||
@ -563,7 +564,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, File... files) {
|
||||
if(ArrayUtil.isEmpty(files)){
|
||||
if (ArrayUtil.isEmpty(files)) {
|
||||
return this;
|
||||
}
|
||||
if (1 == files.length) {
|
||||
@ -656,9 +657,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
*/
|
||||
public Map<String, Resource> fileForm() {
|
||||
final Map<String, Resource> result = MapUtil.newHashMap();
|
||||
this.form.forEach((key, value)->{
|
||||
if(value instanceof Resource){
|
||||
result.put(key, (Resource)value);
|
||||
this.form.forEach((key, value) -> {
|
||||
if (value instanceof Resource) {
|
||||
result.put(key, (Resource) value);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
@ -968,6 +969,19 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
return httpResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行Request请求后,对响应内容后续处理<br>
|
||||
* 处理结束后关闭连接
|
||||
*
|
||||
* @param consumer 响应内容处理函数
|
||||
* @since 5.7.8
|
||||
*/
|
||||
public void then(Consumer<HttpResponse> consumer) {
|
||||
try (HttpResponse response = execute(true)) {
|
||||
consumer.accept(response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单验证,生成的头信息类似于:
|
||||
* <pre>
|
||||
@ -1168,9 +1182,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
|
||||
// Write的时候会优先使用body中的内容,write时自动关闭OutputStream
|
||||
byte[] content;
|
||||
if(ArrayUtil.isNotEmpty(this.bodyBytes)){
|
||||
if (ArrayUtil.isNotEmpty(this.bodyBytes)) {
|
||||
content = this.bodyBytes;
|
||||
} else{
|
||||
} else {
|
||||
content = StrUtil.bytes(getFormUrlEncoded(), this.charset);
|
||||
}
|
||||
IoUtil.write(this.httpConnection.getOutputStream(), true, content);
|
||||
@ -1228,11 +1242,12 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 1. 存在资源对象(fileForm非空)
|
||||
* 2. 用户自定义头为multipart/form-data开头
|
||||
* </pre>
|
||||
*
|
||||
* @return 是否为multipart/form-data表单
|
||||
* @since 5.3.5
|
||||
*/
|
||||
private boolean isMultipart(){
|
||||
if(this.isMultiPart){
|
||||
private boolean isMultipart() {
|
||||
if (this.isMultiPart) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1244,15 +1259,15 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
/**
|
||||
* 将参数加入到form中,如果form为空,新建之。
|
||||
*
|
||||
* @param name 表单属性名
|
||||
* @param name 表单属性名
|
||||
* @param value 属性值
|
||||
* @return this
|
||||
*/
|
||||
private HttpRequest putToForm(String name, Object value){
|
||||
if(null == name || null == value){
|
||||
private HttpRequest putToForm(String name, Object value) {
|
||||
if (null == name || null == value) {
|
||||
return this;
|
||||
}
|
||||
if(null == this.form){
|
||||
if (null == this.form) {
|
||||
this.form = new LinkedHashMap<>();
|
||||
}
|
||||
this.form.put(name, value);
|
||||
|
@ -5,7 +5,6 @@ import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.ssl.SSLSocketFactoryBuilder;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -29,6 +28,14 @@ public class HttpRequestTest {
|
||||
Console.log(body);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getHttpsThenTest() {
|
||||
HttpRequest
|
||||
.get("https://hutool.cn")
|
||||
.then(response -> Console.log(response.body()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getCookiesTest() {
|
||||
@ -126,14 +133,15 @@ public class HttpRequestTest {
|
||||
map.put("size", "2");
|
||||
map.put("sizes", list);
|
||||
|
||||
String s = JSONUtil.toJsonStr(map);
|
||||
HttpRequest request = HttpUtil.createGet("http://localhost:8888/get");
|
||||
Console.log(request.execute().body());
|
||||
HttpRequest
|
||||
.get("http://localhost:8888/get")
|
||||
.form(map)
|
||||
.then(resp -> Console.log(resp.body()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithoutEncodeTest(){
|
||||
public void getWithoutEncodeTest() {
|
||||
String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848";
|
||||
HttpRequest get = HttpUtil.createGet(url);
|
||||
Console.log(get.getUrl());
|
||||
|
Loading…
x
Reference in New Issue
Block a user