refactor(接口测试): POST 支持 multipart/form-data

This commit is contained in:
chenjianxing 2020-10-14 10:55:52 +08:00
parent bc59848dec
commit 08b973c03e
10 changed files with 46 additions and 24 deletions

View File

@ -35,4 +35,6 @@ public class HttpRequest extends Request {
private Long responseTimeout;
@JSONField(ordinal = 16)
private Boolean followRedirects;
@JSONField(ordinal = 17)
private Boolean doMultipartPost;
}

View File

@ -25,6 +25,15 @@ public class TestController {
return jsonObject;
}
@PostMapping(value = "/multipart", consumes = {"multipart/form-data"})
public Object testMultipart(@RequestPart(value = "id") String id, @RequestPart(value = "user") User user, @RequestParam(value = "name") String name) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("user", user.getName());
jsonObject.put("name", name);
return jsonObject;
}
@GetMapping(value = "/{str}")
public Object getString(@PathVariable String str) throws InterruptedException {
if (StringUtils.equals("error", str)) {

@ -1 +1 @@
Subproject commit ee74568be0beba46da19616f5832e83f9164c688
Subproject commit cf6b06526324326a563d933e07118fac014a63b4

View File

@ -39,6 +39,7 @@
:active-text="$t('api_test.request.refer_to_environment')" @change="useEnvironmentChange">
</el-switch>
<el-checkbox class="follow-redirects-item" v-model="request.followRedirects">{{$t('api_test.request.follow_redirects')}}</el-checkbox>
<el-checkbox class="do-multipart-post" v-model="request.doMultipartPost">{{$t('api_test.request.do_multipart_post')}}</el-checkbox>
</el-form-item>
<el-button :disabled="!request.enable || !scenario.enable || isReadOnly" class="debug-button" size="small"
@ -200,31 +201,36 @@ export default {
</script>
<style scoped>
.el-tag {
width: 100%;
height: 40px;
line-height: 40px;
}
.environment-display {
font-size: 14px;
}
.el-tag {
width: 100%;
height: 40px;
line-height: 40px;
}
.environment-name {
font-weight: bold;
font-style: italic;
}
.environment-display {
font-size: 14px;
}
.adjust-margin-bottom {
margin-bottom: 10px;
}
.environment-name {
font-weight: bold;
font-style: italic;
}
.environment-url-tip {
color: #F56C6C;
}
.adjust-margin-bottom {
margin-bottom: 10px;
}
.follow-redirects-item {
margin-left: 30px;
}
.environment-url-tip {
color: #F56C6C;
}
.follow-redirects-item {
margin-left: 30px;
}
.do-multipart-post {
margin-left: 10px;
}
</style>

View File

@ -337,6 +337,7 @@ export class HTTPSamplerProxy extends DefaultTestElement {
}
this.boolProp("HTTPSampler.use_keepalive", options.keepalive, true);
this.boolProp("HTTPSampler.DO_MULTIPART_POST", options.doMultipartPost, false);
}
}

View File

@ -346,6 +346,7 @@ export class HttpRequest extends Request {
this.environment = options.environment;
this.useEnvironment = options.useEnvironment;
this.debugReport = undefined;
this.doMultipartPost = options.doMultipartPost;
this.connectTimeout = options.connectTimeout || 60 * 1000;
this.responseTimeout = options.responseTimeout;
this.followRedirects = options.followRedirects === undefined ? true : options.followRedirects;
@ -987,7 +988,7 @@ class JMXHttpRequest {
this.connectTimeout = request.connectTimeout;
this.responseTimeout = request.responseTimeout;
this.followRedirects = request.followRedirects;
this.doMultipartPost = request.doMultipartPost;
}
}

@ -1 +1 @@
Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1

View File

@ -504,6 +504,7 @@ export default {
connect_timeout: "Connect Timeout",
response_timeout: "Response Timeout",
follow_redirects: "Follow Redirects",
do_multipart_post: "Use multipart/form-data for POST",
body_upload_limit_size: "The file size does not exceed 500 MB",
condition: "condition",
condition_variable: "Variable, e.g: ${var}",

View File

@ -505,6 +505,7 @@ export default {
connect_timeout: "连接超时",
response_timeout: "响应超时",
follow_redirects: "跟随重定向",
do_multipart_post: "对 POST 使用 multipart/form-data",
body_upload_limit_size: "上传文件大小不能超过 500 MB!",
condition: "条件",
condition_variable: "变量,例如: ${var}",

View File

@ -505,6 +505,7 @@ export default {
connect_timeout: "連接超時",
response_timeout: "響應超時",
follow_redirects: "跟隨重定向",
do_multipart_post: "對 POST 使用 multipart/form-data",
body_upload_limit_size: "上傳文件大小不能超過 500 MB!",
condition: "條件",
condition_variable: "變量,例如: ${var}",