mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add request config
This commit is contained in:
@@ -217,7 +217,7 @@ public class DownloadTest {
|
||||
public void downloadTeamViewerTest() throws IOException {
|
||||
// 此URL有3次重定向, 需要请求4次
|
||||
final String url = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe";
|
||||
HttpGlobalConfig.setMaxRedirectCount(20);
|
||||
HttpGlobalConfig.setMaxRedirects(20);
|
||||
final Path temp = Files.createTempFile("tmp", ".exe");
|
||||
final File file = HttpDownloader.downloadFile(url, temp.toFile());
|
||||
Console.log(file.length());
|
||||
|
@@ -98,7 +98,7 @@ public class HttpUtilTest {
|
||||
public void get12306Test() {
|
||||
// 某些网站需要打开信任全部域
|
||||
// HttpGlobalConfig.setTrustAnyHost(true);
|
||||
HttpUtil.send(Request.of("https://kyfw.12306.cn/otn/").setMaxRedirectCount(2))
|
||||
HttpUtil.send(Request.of("https://kyfw.12306.cn/otn/").setMaxRedirects(2))
|
||||
.then(response -> Console.log(response.bodyStr()));
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ public class IssueI5TPSYTest {
|
||||
public void redirectTest() {
|
||||
final String url = "https://bsxt.gdzwfw.gov.cn/UnifiedReporting/auth/newIndex";
|
||||
final Response res = HttpUtil.send(Request.of(url)
|
||||
.setMaxRedirectCount(2)
|
||||
.setMaxRedirects(2)
|
||||
.header(HeaderName.USER_AGENT, "PostmanRuntime/7.29.2")
|
||||
.cookie("jsessionid=s%3ANq6YTcIHQWrHkEqOSxiQNijDMhoFNV4_.h2MVD1CkW7sOZ60OSnPs7m4K%2FhENfYy%2FdzjKvSiZF4E"));
|
||||
Console.log(res.body());
|
||||
|
@@ -168,12 +168,12 @@ public class RequestTest {
|
||||
// String url = "https://api.btstu.cn/sjtx/api.php?lx=b1";
|
||||
|
||||
// 方式1:全局设置
|
||||
HttpGlobalConfig.setMaxRedirectCount(1);
|
||||
HttpGlobalConfig.setMaxRedirects(1);
|
||||
Response execute = Request.of(url).send();
|
||||
Console.log(execute.getStatus(), execute.header(HeaderName.LOCATION));
|
||||
|
||||
// 方式2,单独设置
|
||||
execute = Request.of(url).setMaxRedirectCount(1).send();
|
||||
execute = Request.of(url).setMaxRedirects(1).send();
|
||||
Console.log(execute.getStatus(), execute.header(HeaderName.LOCATION));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user