diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java b/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java index bcaf1160a4..ec14e45842 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/curl/constants/CurlPatternConstants.java @@ -52,7 +52,8 @@ public interface CurlPatternConstants { /** * --data-raw 请求体 */ - Pattern HTTP_ROW_BODY_PATTERN = Pattern.compile("--data-raw '(.+?)'(?s)", Pattern.DOTALL); + Pattern HTTP_XML_JSON_BODY_PATTERN = Pattern.compile("--data-raw '(.+?)'(?s)", Pattern.DOTALL); + Pattern HTTP_ROW_BODY_PATTERN = Pattern.compile("--data-binary\\s+['\"](.+?)['\"](?s)", Pattern.DOTALL); /** * --form 请求体 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java index f76f654f40..2508d77315 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/curl/handler/HttpBodyHandler.java @@ -50,9 +50,15 @@ public class HttpBodyHandler extends CurlHandlerChain { entity.setBody(parseUrlEncodeBody(urlencodeMatcher)); } + Matcher xmlJsonMatcher = CurlPatternConstants.HTTP_XML_JSON_BODY_PATTERN.matcher(curl); + if (xmlJsonMatcher.find()) { + entity.setBody(parseRowBody(xmlJsonMatcher, entity)); + } + Matcher rawMatcher = CurlPatternConstants.HTTP_ROW_BODY_PATTERN.matcher(curl); if (rawMatcher.find()) { - entity.setBody(parseRowBody(rawMatcher, entity)); + entity.setBodyType(Body.BodyType.RAW.name()); + entity.setBody(rawMatcher.group(1)); } Matcher defaultMatcher = CurlPatternConstants.DEFAULT_HTTP_BODY_PATTERN.matcher(curl); diff --git a/frontend/src/views/api-test/components/utils.ts b/frontend/src/views/api-test/components/utils.ts index 9549b30401..89d93e3105 100644 --- a/frontend/src/views/api-test/components/utils.ts +++ b/frontend/src/views/api-test/components/utils.ts @@ -298,6 +298,13 @@ export function parseCurlBody(bodyType: RequestBodyFormat, body: Record