mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user