fix(接口测试): 导入请求体格式是json的jmx格式的接口,导入后默认请求体格式是raw

--bug=1010910
--user=李玉号
【接口测试】github#11218,【接口测试】导入请求体格式是json的jmx格式的接口,导入后默认请求体格式是raw;自定义脚本修改成json格式后导入默认请求体格式是x-www-form-urlencoded
https://www.tapd.cn/55049933/s/1115431

Closes #11218
This commit is contained in:
shiziyuan9527 2022-03-09 10:44:10 +08:00 committed by shiziyuan9527
parent b1ddc4016f
commit f4907da833
1 changed files with 14 additions and 1 deletions

View File

@ -718,7 +718,20 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
String bodyType = this.getBodyType(samplerProxy.getHeaders());
if (source.getArguments() != null) {
if (source.getPostBodyRaw()) {
samplerProxy.getBody().setType(Body.RAW);
List<KeyValue> 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)) {