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