This commit is contained in:
Looly
2024-07-04 21:26:01 +08:00
parent 1a1884a04c
commit 34b322e3fc
10 changed files with 135 additions and 134 deletions

View File

@@ -185,10 +185,9 @@ public class HttpUtilTest {
@Test
@Disabled
public void getPicTest(){
HttpGlobalConfig.setDecodeUrl(false);
final String url = "https://p3-sign.douyinpic.com/tos-cn-i-0813/f41afb2e79a94dcf80970affb9a69415~noop.webp?x-expires=1647738000&x-signature=%2Br1ekUCGjXiu50Y%2Bk0MO4ovulK8%3D&from=4257465056&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sh=&sc=&l=2022021809224601020810013524310DD3&biz_tag=aweme_images";
final String body = HttpUtil.send(Request.of(url)).bodyStr();
final String body = HttpUtil.send(Request.of(url, null)).bodyStr();
Console.log(body);
}

View File

@@ -31,13 +31,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@link Request}单元测试
*
* @author Looly
*/
@SuppressWarnings("resource")
public class HttpRequestTest {
public class RequestTest {
final String url = "http://photo.qzone.qq.com/fcgi-bin/fcg_list_album?uin=88888&outstyle=2";
@Test
@@ -238,4 +240,21 @@ public class HttpRequestTest {
final Response httpResponse = Request.of("http://82.157.17.173:8100/app/getAddress").send();
Console.log(httpResponse.body());
}
@Test
void percentTest() {
// 此处URL有歧义
// 如果用户需要传的a的值为`%`则这个URL表示已经编码过了此时需要解码后再重新编码保持不变
Request request = Request.of("http://localhost:9999/a?a=%25", CharsetUtil.UTF_8);
assertEquals("http://localhost:9999/a?a=%25", request.handledUrl().toURL().toString());
// 不传charset则保留原样不做任何处理
request = Request.of("http://localhost:9999/a?a=%25", null);
assertEquals("http://localhost:9999/a?a=%25", request.handledUrl().toURL().toString());
// 如果用户需要传的a的值为`%25`则这个URL表示未编码不需要解码需要对`%`再次编码
request = Request.of("http://localhost:9999/a?a=%25", null);
request.setEncodeUrl(true);
assertEquals("http://localhost:9999/a?a=%2525", request.handledUrl().toURL().toString());
}
}