From 1609701cb186241fac538344500036b6bb0a5c18 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Mon, 15 Jul 2024 18:24:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmock-server=E8=A7=A3=E6=9E=90=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=E6=8A=A5=E9=94=99=E7=9A=84=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/api/utils/MockServerUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/MockServerUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/MockServerUtils.java index db3d6e76ae..af6221732c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/MockServerUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/MockServerUtils.java @@ -46,12 +46,13 @@ public class MockServerUtils { try { if (request instanceof ShiroHttpServletRequest shiroHttpServletRequest) { + String contentType = StringUtils.isBlank(request.getContentType()) ? StringUtils.EMPTY : request.getContentType(); List contentTypeLists = List.of(MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.TEXT_PLAIN_VALUE); - if (StringUtils.equals(request.getContentType(), MediaType.APPLICATION_OCTET_STREAM_VALUE)) { + if (StringUtils.equals(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE)) { InputStream inputStream = shiroHttpServletRequest.getRequest().getInputStream(); byte[] binaryParams = inputStream.readAllBytes(); requestParam.setBinaryParamsObj(binaryParams); - } else if (contentTypeLists.contains(request.getContentType())) { + } else if (contentTypeLists.contains(contentType)) { String inputLine; StringBuilder receiveData = new StringBuilder(); try (BufferedReader in = new BufferedReader(new InputStreamReader( @@ -61,7 +62,7 @@ public class MockServerUtils { } } requestPostString = receiveData.toString(); - } else if (StringUtils.equals(request.getContentType(), MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { + } else if (StringUtils.equals(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { Map parameterMap = request.getParameterMap(); LinkedHashMap bodyParams = new LinkedHashMap<>(); if (parameterMap != null && !parameterMap.isEmpty()) {