1
0
chenendian 6 дней назад
Родитель
Сommit
1d15baa636

+ 8 - 4
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceFileUtil.java

@@ -21,6 +21,7 @@ import java.util.zip.ZipOutputStream;
 
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.web.util.UriComponentsBuilder;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -314,10 +315,13 @@ public class ServiceFileUtil {
      * @throws IOException
      */
     public static void downloadFile(String fileURL,String fileName, String destinationPath) throws IOException {
-        String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
-        String newUrl = fileURL.replaceAll("&fileName=[^&]*$", "");
-        // 拼接合法URL
-        String fullUrl = newUrl + "&fileName=" + encodeFileName;
+
+        String fullUrl = UriComponentsBuilder.fromHttpUrl(fileURL)
+                .replaceQueryParam("fileName", fileName)
+                .build()
+                .toUriString();
+
+
         URL url = new URL(fullUrl);
         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
         connection.setRequestMethod("GET");