fix(接口测试): 修复自定义请求前面有空格请求错误的缺陷

--bug=1027697 --user=王孝刚
【接口测试】github#25505,【接口自动化】场景里添加“自定义请求”,请求地址http前有个空格,然后发出去的请求就不对
https://www.tapd.cn/55049933/s/1391702
This commit is contained in:
wxg0103 2023-07-11 18:07:30 +08:00 committed by fit2-zhao
parent 0433a12596
commit f5e09b8e4d
2 changed files with 16 additions and 4 deletions

View File

@ -402,7 +402,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (StringUtils.isEmpty(url)) {
MSException.throwException("当前步骤:" + this.getName() + " 环境为空,请重新选择环境");
}
String envPath = url;
String envPath = "";
try {
URL urlObject = new URL(url);
if (url.contains("${")){
envPath = url;
} else {
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8.name()));
envPath = urlObject.getPath();
}
sampler.setProtocol(urlObject.getProtocol());
} catch (Exception e) {
envPath = url;
}
sampler.setProperty("HTTPSampler.path", envPath, StandardCharsets.UTF_8.name());
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
envPath = getRestParameters(URLDecoder.decode(URLEncoder.encode(envPath, StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name()));

View File

@ -268,9 +268,6 @@ export default {
},
urlChange() {
if (!this.debugForm.url) return;
if (!this.debugForm.url.startsWith("http")) {
this.debugForm.url = "http://" + this.debugForm.url;
}
let url = this.getURL(this.debugForm.url);
if (url && url.pathname) {
if (this.debugForm.url.indexOf('?') != -1) {
@ -306,6 +303,9 @@ export default {
}
return url;
} catch (e) {
if (!urlStr.startsWith("http") || !urlStr.startsWith("https")) {
urlStr = "http://" + urlStr;
}
return urlStr;
}
},