fix redirect bug

This commit is contained in:
Looly
2024-12-03 00:35:23 +08:00
parent 9cc75d5e34
commit 4aa6f799b2
7 changed files with 164 additions and 68 deletions

View File

@@ -26,7 +26,6 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
/**
@@ -203,7 +202,19 @@ public class DownloadTest {
@Test
@Disabled
public void downloadTeamViewerTest() throws IOException {
public void downloadTeamViewerByOkHttpTest() {
// 此URL有3次重定向, 需要请求4次
final String url = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe";
HttpGlobalConfig.setMaxRedirects(2);
final Response send = Request.of(url).send(ClientEngineFactory.createEngine("okhttp"));
Console.log(send.getStatus());
Console.log(send.headers());
}
@Test
@Disabled
public void downloadTeamViewerByJdkTest() {
// 此URL有3次重定向, 需要请求4次
final String url = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe";
HttpGlobalConfig.setMaxRedirects(2);
@@ -212,4 +223,16 @@ public class DownloadTest {
Console.log(send.getStatus());
Console.log(send.headers());
}
@Test
@Disabled
public void downloadTeamViewerByHttpClient5Test() {
// 此URL有3次重定向, 需要请求4次
final String url = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe";
HttpGlobalConfig.setMaxRedirects(2);
final Response send = Request.of(url).send(ClientEngineFactory.createEngine("HttpClient5"));
Console.log(send.getStatus());
Console.log(send.headers());
}
}