diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java index ed54de8e5e..ade15abc36 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java @@ -21,6 +21,7 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import java.io.InputStream; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -75,6 +76,11 @@ public class HarParser extends HarAbstractParser { if (harRequest.url != null) { String[] nameArr = harRequest.url.split("/"); reqName = nameArr[nameArr.length - 1]; + //然后进行转码解码 + try { + reqName = URLDecoder.decode(reqName,"UTF-8"); + }catch (Exception e){ + } } if (harRequest != null) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/har/HarUtils.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/har/HarUtils.java index f6cd6b0f41..e7fed00d19 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/har/HarUtils.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/har/HarUtils.java @@ -29,6 +29,9 @@ import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; /** * Utility class for working with HAR files. @@ -51,4 +54,13 @@ public class HarUtils { Har har = JSONObject.parseObject(harJson, Har.class); return har; } + + public static void main(String[] args) throws UnsupportedEncodingException { +// String str = "%E6%B5%8B%AF"; + String str = "测试"; + str = URLEncoder.encode(str,"UTF-8"); + System.out.println(str); + str = URLDecoder.decode(str,"UTF-8"); + System.out.println(str); + } }