mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -8,7 +8,7 @@ import org.dromara.hutool.core.net.url.UrlBuilder;
|
||||
import org.dromara.hutool.core.util.CharsetUtil;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.client.Response;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.dromara.hutool.http.meta.Method;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@@ -99,9 +99,9 @@ public class HttpRequestTest {
|
||||
@Disabled
|
||||
public void getDeflateTest() {
|
||||
final Response res = Request.of("https://comment.bilibili.com/67573272.xml")
|
||||
.header(Header.ACCEPT_ENCODING, "deflate")
|
||||
.header(HeaderName.ACCEPT_ENCODING, "deflate")
|
||||
.send();
|
||||
Console.log(res.header(Header.CONTENT_ENCODING));
|
||||
Console.log(res.header(HeaderName.CONTENT_ENCODING));
|
||||
Console.log(res.body());
|
||||
}
|
||||
|
||||
@@ -156,11 +156,11 @@ public class HttpRequestTest {
|
||||
// 方式1:全局设置
|
||||
HttpGlobalConfig.setMaxRedirectCount(1);
|
||||
Response execute = Request.of(url).send();
|
||||
Console.log(execute.getStatus(), execute.header(Header.LOCATION));
|
||||
Console.log(execute.getStatus(), execute.header(HeaderName.LOCATION));
|
||||
|
||||
// 方式2,单独设置
|
||||
execute = Request.of(url).setMaxRedirectCount(1).send();
|
||||
Console.log(execute.getStatus(), execute.header(Header.LOCATION));
|
||||
Console.log(execute.getStatus(), execute.header(HeaderName.LOCATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -5,7 +5,7 @@ import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.regex.ReUtil;
|
||||
import org.dromara.hutool.core.util.CharsetUtil;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.dromara.hutool.http.meta.Method;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@@ -39,7 +39,7 @@ public class HttpUtilTest {
|
||||
// 某些接口对Accept头有特殊要求,此处自定义头
|
||||
final String result = HttpUtil.send(Request
|
||||
.of("http://cmp.ishanghome.com/cmp/v1/community/queryClusterCommunity")
|
||||
.header(Header.ACCEPT, "*/*"))
|
||||
.header(HeaderName.ACCEPT, "*/*"))
|
||||
.bodyStr();
|
||||
Console.log(result);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class HttpUtilTest {
|
||||
// 自定义的默认header无效
|
||||
final String result = Request
|
||||
.of("https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101457313&redirect_uri=http%3A%2F%2Fwww.benmovip.com%2Fpay-cloud%2Fqqlogin%2FgetCode&state=ok")
|
||||
.header(Header.USER_AGENT, null).send().bodyStr();
|
||||
.header(HeaderName.USER_AGENT, null).send().bodyStr();
|
||||
Console.log(result);
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package org.dromara.hutool.http;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.client.Response;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class IssueI5TPSYTest {
|
||||
final String url = "https://bsxt.gdzwfw.gov.cn/UnifiedReporting/auth/newIndex";
|
||||
final Response res = HttpUtil.send(Request.of(url)
|
||||
.setMaxRedirectCount(2)
|
||||
.header(Header.USER_AGENT, "PostmanRuntime/7.29.2")
|
||||
.header(HeaderName.USER_AGENT, "PostmanRuntime/7.29.2")
|
||||
.cookie("jsessionid=s%3ANq6YTcIHQWrHkEqOSxiQNijDMhoFNV4_.h2MVD1CkW7sOZ60OSnPs7m4K%2FhENfYy%2FdzjKvSiZF4E"));
|
||||
Console.log(res.body());
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package org.dromara.hutool.http;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.client.Response;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.brotli.dec.BrotliInputStream;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -17,7 +17,7 @@ public class IssueI5XBCFTest {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
final Response s = Request.of("https://static-exp1.licdn.com/sc/h/br/1cp0oqz322bdprj3qd4pojqix")
|
||||
.header(Header.ACCEPT_ENCODING, "br")
|
||||
.header(HeaderName.ACCEPT_ENCODING, "br")
|
||||
.send();
|
||||
Console.log(s.body());
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package org.dromara.hutool.http;
|
||||
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.dromara.hutool.http.meta.Method;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -24,7 +24,7 @@ public class RestTest {
|
||||
.body(JSONUtil.ofObj()
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
Assertions.assertEquals("application/json;charset=UTF-8", request.header(Header.CONTENT_TYPE));
|
||||
Assertions.assertEquals("application/json;charset=UTF-8", request.header(HeaderName.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@@ -52,7 +52,7 @@ public class RestTest {
|
||||
@Disabled
|
||||
public void getWithBodyTest() {
|
||||
final Request request = Request.of("http://localhost:8888/restTest")//
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.header(HeaderName.CONTENT_TYPE, "application/json")
|
||||
.body(JSONUtil.ofObj()
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
|
@@ -6,7 +6,7 @@ import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.http.client.Request;
|
||||
import org.dromara.hutool.http.client.Response;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.dromara.hutool.http.meta.Method;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -69,7 +69,7 @@ public class UploadTest {
|
||||
//noinspection resource
|
||||
final String result = Request.of(url)
|
||||
.method(Method.POST)
|
||||
.header(Header.USER_AGENT, "PostmanRuntime/7.28.4")
|
||||
.header(HeaderName.USER_AGENT, "PostmanRuntime/7.28.4")
|
||||
.auth(token)
|
||||
.form(MapUtil.of("smfile", FileUtil.file("d:/test/qrcodeCustom.png")))
|
||||
.send().bodyStr();
|
||||
|
@@ -2,24 +2,24 @@ package org.dromara.hutool.http.server;
|
||||
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.http.HttpUtil;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
|
||||
public class RedirectServerTest {
|
||||
public static void main(final String[] args) {
|
||||
HttpUtil.createServer(8888).addAction("/redirect1", (request, response) -> {
|
||||
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect2");
|
||||
response.addHeader(Header.SET_COOKIE.getValue(),"redirect1=1; path=/; HttpOnly");
|
||||
response.addHeader(HeaderName.LOCATION.getValue(),"http://localhost:8888/redirect2");
|
||||
response.addHeader(HeaderName.SET_COOKIE.getValue(),"redirect1=1; path=/; HttpOnly");
|
||||
response.send(301);
|
||||
}).addAction("/redirect2", (request, response) -> {
|
||||
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect3");
|
||||
response.addHeader(Header.SET_COOKIE.getValue(), "redirect2=2; path=/; HttpOnly");
|
||||
response.addHeader(HeaderName.LOCATION.getValue(),"http://localhost:8888/redirect3");
|
||||
response.addHeader(HeaderName.SET_COOKIE.getValue(), "redirect2=2; path=/; HttpOnly");
|
||||
response.send(301);
|
||||
}).addAction("/redirect3", (request, response) -> {
|
||||
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect4");
|
||||
response.addHeader(Header.SET_COOKIE.getValue(),"redirect3=3; path=/; HttpOnly");
|
||||
response.addHeader(HeaderName.LOCATION.getValue(),"http://localhost:8888/redirect4");
|
||||
response.addHeader(HeaderName.SET_COOKIE.getValue(),"redirect3=3; path=/; HttpOnly");
|
||||
response.send(301);
|
||||
}).addAction("/redirect4", (request, response) -> {
|
||||
final String cookie = request.getHeader(Header.COOKIE);
|
||||
final String cookie = request.getHeader(HeaderName.COOKIE);
|
||||
Console.log(cookie);
|
||||
response.sendOk();
|
||||
}).start();
|
||||
|
@@ -5,7 +5,7 @@ import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.net.multipart.UploadFile;
|
||||
import org.dromara.hutool.http.meta.ContentType;
|
||||
import org.dromara.hutool.http.meta.Header;
|
||||
import org.dromara.hutool.http.meta.HeaderName;
|
||||
import org.dromara.hutool.http.HttpUtil;
|
||||
import org.dromara.hutool.json.JSONUtil;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SimpleServerTest {
|
||||
res.write("0");
|
||||
Console.log("Write 0 OK");
|
||||
}).addAction("/getCookie", ((request, response) -> {
|
||||
response.setHeader(Header.SET_COOKIE.toString(),
|
||||
response.setHeader(HeaderName.SET_COOKIE.toString(),
|
||||
ListUtil.of(
|
||||
new HttpCookie("cc", "123").toString(),
|
||||
new HttpCookie("cc", "abc").toString()));
|
||||
|
Reference in New Issue
Block a user