From 63c8e87e2bd402ed7a540ef98bd9b649378a9148 Mon Sep 17 00:00:00 2001 From: dai_48k <1981669259@qq.com> Date: Tue, 18 Mar 2025 10:52:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0urlencode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +--- .idea/.gitignore | 8 ++++++++ .idea/compiler.xml | 14 +++++++++++++ .idea/dataSources.xml | 12 +++++++++++ .idea/encodings.xml | 6 ++++++ .idea/jarRepositories.xml | 20 +++++++++++++++++++ .idea/misc.xml | 14 +++++++++++++ .idea/vcs.xml | 6 ++++++ .../dreamcenter/webdav/util/WebDavUtil.java | 10 +++++++++- webdav.iml | 2 ++ 10 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/dataSources.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 webdav.iml diff --git a/.gitignore b/.gitignore index d803c5f..78c175b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ config.properties .mvn -.idea target -directory.db -webdav.iml \ No newline at end of file +directory.db \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..3864f88 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..f19abed --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/directory.db + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/top/dreamcenter/webdav/util/WebDavUtil.java b/src/main/java/top/dreamcenter/webdav/util/WebDavUtil.java index e4abb3f..413d54c 100644 --- a/src/main/java/top/dreamcenter/webdav/util/WebDavUtil.java +++ b/src/main/java/top/dreamcenter/webdav/util/WebDavUtil.java @@ -6,6 +6,7 @@ import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.entity.ContentType; import org.apache.http.entity.FileEntity; import org.apache.http.impl.client.BasicCredentialsProvider; @@ -16,6 +17,8 @@ import top.dreamcenter.webdav.bean.SendResult; import top.dreamcenter.webdav.prop.WebDavConfig; import java.io.File; +import java.net.URLEncoder; +import java.util.Arrays; /** * WebDav工具 @@ -37,7 +40,7 @@ public class WebDavUtil { .build(); try { // 创建PUT请求 - HttpPut httpPut = new HttpPut(WebDavConfig.getUrl() + "/" + davName); + HttpPut httpPut = new HttpPut(WebDavConfig.getUrl() + "/" + encodeURL(davName)); FileEntity fileEntity = new FileEntity(file, ContentType.DEFAULT_BINARY); // 或者根据需要选择正确的ContentType httpPut.setEntity(fileEntity); // 执行请求 @@ -69,4 +72,9 @@ public class WebDavUtil { private static String responseEntityToString(HttpEntity entity) throws Exception { return EntityUtils.toString(entity, "UTF-8"); // 需要Apache HttpCore的依赖来使用这个方法 } + + private static String encodeURL(String raw) { + String[] split = raw.split("/"); + return URLEncodedUtils.formatSegments(split); + } } diff --git a/webdav.iml b/webdav.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/webdav.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file