From deb2d98a2e626023f255a553698d3522a49ba41b Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 10 May 2024 17:27:19 +0800 Subject: [PATCH] =?UTF-8?q?HttpRequest#get=E4=B8=8D=E5=86=8D=E5=B0=9D?= =?UTF-8?q?=E8=AF=95File=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../java/cn/hutool/core/net/url/UrlBuilder.java | 2 +- .../main/java/cn/hutool/core/util/URLUtil.java | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f4ca5c2a..be5288eca 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * 【poi 】 增加ExcelWriter.addIgnoredErrors,支持忽略警告小标 * 【core 】 PropertyComparator增加compareSelf构造重载(issue#3569@Github) * 【db 】 增加OceanBase的driver推断(pr#1217@Gitee) +* 【http 】 HttpRequest#get不再尝试File路径(issue#I9O6DA@Gitee) ### 🐞Bug修复 * 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github) diff --git a/hutool-core/src/main/java/cn/hutool/core/net/url/UrlBuilder.java b/hutool-core/src/main/java/cn/hutool/core/net/url/UrlBuilder.java index 018019987..6ac3593d9 100755 --- a/hutool-core/src/main/java/cn/hutool/core/net/url/UrlBuilder.java +++ b/hutool-core/src/main/java/cn/hutool/core/net/url/UrlBuilder.java @@ -135,7 +135,7 @@ public final class UrlBuilder implements Builder { */ public static UrlBuilder of(String url, Charset charset) { Assert.notBlank(url, "Url must be not blank!"); - return of(URLUtil.url(StrUtil.trim(url)), charset); + return of(URLUtil.urlForNet(StrUtil.trim(url)), charset); } /** diff --git a/hutool-core/src/main/java/cn/hutool/core/util/URLUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/URLUtil.java index f4d384a61..a57ada640 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/URLUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/URLUtil.java @@ -164,6 +164,22 @@ public class URLUtil extends URLEncodeUtil { } } + /** + * 根据提供的路径创建一个URL对象,如果给定路径非网络协议路径直接抛出异常 + * + * @param path 表示URL路径的字符串。 + * @return 返回一个新创建的URL对象。 + * @throws UtilException 如果给定的路径不能构造一个有效的URL,则抛出UtilException。 + * @since 5.8.28 + */ + public static URL urlForNet(String path) throws UtilException{ + try { + return new URL(path); + } catch (MalformedURLException e) { + throw new UtilException(e); + } + } + /** * 获取string协议的URL,类似于string:///xxxxx *