网络请求工具bug修改

This commit is contained in:
2022-02-07 17:31:12 +08:00
parent 38416ff420
commit ddf4b4bc07
2 changed files with 19 additions and 35 deletions

View File

@@ -12,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.HashMap;
import java.util.Map;
import static java.lang.Thread.sleep;
@SpringBootTest(classes = MainApplication.class)
@@ -21,11 +24,18 @@ public class NetworkTest {
HttpService httpService;
private final Logger logger = LoggerFactory.getLogger(NetworkTest.class);
private static final String STATION_NAME_URL = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.9226";
@Test
@Timeout(3000)
public void testGet() throws InterruptedException {
Msg<String> msg = httpService.doGet("https://baidu.com");
Map<String, String> header = new HashMap<>(1);
// header.put("Accept", "*/*");
header.put("Connection", "keep-alive");
// header.put("User-Agent", "PostmanRuntime/7.29.0");
// header.put("Accept-Encoding", "gzip, deflate, br");
Msg<String> msg = httpService.doGet(STATION_NAME_URL, header, null);
logger.info("GET测试{}", msg);
assert msg.isSuccess();
}