From f4907da8333fbe9bad1207c4994bd84c379ca9f1 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 9 Mar 2022 10:44:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E8=AF=B7=E6=B1=82=E4=BD=93=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=98=AFjson=E7=9A=84jmx=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=AF=BC=E5=85=A5=E5=90=8E=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=BD=93=E6=A0=BC=E5=BC=8F=E6=98=AFraw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1010910 --user=李玉号 【接口测试】github#11218,【接口测试】导入请求体格式是json的jmx格式的接口,导入后默认请求体格式是raw;自定义脚本修改成json格式后导入默认请求体格式是x-www-form-urlencoded https://www.tapd.cn/55049933/s/1115431 Closes #11218 --- .../definition/parse/JmeterDefinitionParser.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java index 24be1b96d8..60ffd132ca 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/JmeterDefinitionParser.java @@ -718,7 +718,20 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser headers = samplerProxy.getHeaders(); + boolean jsonType = false; + if (CollectionUtils.isNotEmpty(headers)) { + for (KeyValue header : headers) { + if (StringUtils.equals(header.getName(), "Content-Type") && StringUtils.equals(header.getValue(), "application/json")) { + samplerProxy.getBody().setType(Body.JSON); + jsonType = true; + break; + } + } + } + if (!jsonType) { + samplerProxy.getBody().setType(Body.RAW); + } source.getArguments().getArgumentsAsMap().forEach((k, v) -> samplerProxy.getBody().setRaw(v)); samplerProxy.getBody().initKvs(); } else if (StringUtils.isNotEmpty(bodyType) || ("POST".equalsIgnoreCase(source.getMethod()) && source.getArguments().getArgumentsAsMap().size() > 0)) {