From 01e4cacb2b6426bff77e92fa799e636768c6f929 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 10 Jul 2023 11:48:00 +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=8Dpost=E8=AF=B7=E6=B1=82=E6=9C=AA=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5path=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1027640 --user=王孝刚 【接口测试】接口定义-post请求报错不支持 https://www.tapd.cn/55049933/s/1390715 --- .../request/sampler/MsHTTPSamplerProxy.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 2b63e3c70b..964ad6f229 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -428,12 +428,16 @@ public class MsHTTPSamplerProxy extends MsTestElement { try { URL urlObject = new URL(url); if (StringUtils.isNotBlank(this.getPath())) { - envPath += this.getPath(); + envPath = this.getPath().startsWith("/") ? this.getPath() : StringUtils.join("/", this.getPath()); } if (httpConfig.getSocket().contains("${")) { envPath = StringUtils.isNotBlank(this.path) ? StringUtils.join(url, this.path) : url; } else if (StringUtils.isNotEmpty(urlObject.getHost())) { - envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile(); + if (StringUtils.isNotBlank(urlObject.getPath()) && urlObject.getPath().endsWith("/")) { + envPath = StringUtils.join(urlObject.getPath().substring(0, urlObject.getPath().length() - 1), envPath); + } else { + envPath = StringUtils.join(urlObject.getPath(), envPath); + } sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); sampler.setProtocol(httpConfig.getProtocol()); sampler.setPort(urlObject.getPort()); @@ -451,9 +455,6 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name())); sampler.setProtocol(urlObject.getProtocol()); } - /*if (StringUtils.isNotEmpty(envPath) && !envPath.startsWith("/")) { - envPath = "/" + envPath; - }*/ sampler.setProperty("HTTPSampler.path", URLDecoder.decode(URLEncoder.encode(envPath, StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name())); } }