add request config

This commit is contained in:
Looly
2024-09-05 21:17:10 +08:00
parent c314b4e183
commit c958553e76
11 changed files with 80 additions and 29 deletions

View File

@@ -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());

View File

@@ -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()));
}

View File

@@ -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());

View File

@@ -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));
}