增加post内容

This commit is contained in:
random-chat
2022-02-12 15:52:34 +08:00
parent ab51b25c20
commit e8729f831d
7 changed files with 80 additions and 1 deletions

View File

@@ -25,10 +25,12 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder; import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import java.io.IOException; import java.io.IOException;
@@ -296,6 +298,9 @@ public class HttpCollectImpl extends AbstractCollect {
log.error("not support the http method: {}.", httpProtocol.getMethod()); log.error("not support the http method: {}.", httpProtocol.getMethod());
return null; return null;
} }
String contentType = null;
// params // params
Map<String, String> params = httpProtocol.getParams(); Map<String, String> params = httpProtocol.getParams();
if (params != null && !params.isEmpty()) { if (params != null && !params.isEmpty()) {
@@ -303,6 +308,7 @@ public class HttpCollectImpl extends AbstractCollect {
requestBuilder.addParameter(param.getKey(), param.getValue()); requestBuilder.addParameter(param.getKey(), param.getValue());
} }
} }
// headers // headers
Map<String, String> headers = httpProtocol.getHeaders(); Map<String, String> headers = httpProtocol.getHeaders();
if (headers != null && !headers.isEmpty()) { if (headers != null && !headers.isEmpty()) {
@@ -332,7 +338,11 @@ public class HttpCollectImpl extends AbstractCollect {
String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken(); String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken();
requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value); requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value);
} }
// todo 处理请求内容 body 暂不支持body
// 请求内容会覆盖post协议的params
if(StringUtils.hasLength(httpProtocol.getPayload())){
requestBuilder.setEntity(new StringEntity(httpProtocol.getPayload(),"UTF-8"));
}
// uri // uri
if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) { if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) {

View File

@@ -45,6 +45,11 @@ public class HttpProtocol {
* http请求携带查询参数 eg: localhost:80/api?paramKey=value * http请求携带查询参数 eg: localhost:80/api?paramKey=value
*/ */
private Map<String, String> params; private Map<String, String> params;
/**
* http请求携带的请求体
*/
private String payload;
/** /**
* 认证信息 * 认证信息
*/ */

View File

@@ -169,6 +169,7 @@ public class MonitorServiceImpl implements MonitorService {
} }
param.setType(CommonConstants.PARAM_TYPE_NUMBER); param.setType(CommonConstants.PARAM_TYPE_NUMBER);
break; break;
case "textarea":
case "text": case "text":
Short limit = paramDefine.getLimit(); Short limit = paramDefine.getLimit();
if (limit != null) { if (limit != null) {

View File

@@ -20,6 +20,10 @@ configmap:
type: 1 type: 1
- key: password - key: password
type: 2 type: 2
- key: contentType
type: 1
- key: payload
type: 1
# 指标组列表 # 指标组列表
metrics: metrics:
# 第一个监控指标组 cpu # 第一个监控指标组 cpu
@@ -48,6 +52,10 @@ metrics:
method: ^_^method^_^ method: ^_^method^_^
# 是否启用ssl/tls,即是http还是https,默认false # 是否启用ssl/tls,即是http还是https,默认false
ssl: ^_^ssl^_^ ssl: ^_^ssl^_^
payload: ^_^payload^_^
# 请求头内容
headers:
content-type: ^_^contentType^_^
# 认证 # 认证
authorization: authorization:
# 认证方式: Basic Auth, Digest Auth, Bearer Token # 认证方式: Basic Auth, Digest Auth, Bearer Token

View File

@@ -37,6 +37,10 @@ param:
value: PUT value: PUT
- label: DELETE请求 - label: DELETE请求
value: DELETE value: DELETE
- field: contentType
name: Content-Type
type: text
required: false
- field: username - field: username
name: 用户名 name: 用户名
type: text type: text
@@ -52,3 +56,7 @@ param:
# 当type为boolean时,前端用switch展示开关 # 当type为boolean时,前端用switch展示开关
type: boolean type: boolean
required: true required: true
- field: payload
name: 请求BODY
type: textarea
required: false

View File

@@ -63,6 +63,30 @@
/> />
</nz-form-control> </nz-form-control>
<nz-form-label
*ngIf="paramDefine.type === 'textarea'"
nzSpan="7"
[nzRequired]="paramDefine.required"
[nzFor]="paramDefine.field"
>{{ paramDefine.name }}
</nz-form-label>
<nz-form-control
*ngIf="paramDefine.type === 'textarea'"
nzSpan="8"
[nzErrorTip]="'validation.required' | i18n"
>
<textarea
nz-input
[(ngModel)]="params[i].value"
[required]="paramDefine.required"
[name]="paramDefine.field"
[id]="paramDefine.field"
[placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
rows="3"
></textarea>
</nz-form-control>
<nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field" <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
>{{ paramDefine.name }} >{{ paramDefine.name }}
</nz-form-label> </nz-form-label>

View File

@@ -72,6 +72,29 @@
/> />
</nz-form-control> </nz-form-control>
<nz-form-label
*ngIf="paramDefine.type === 'textarea'"
nzSpan="7"
[nzRequired]="paramDefine.required"
[nzFor]="paramDefine.field"
>{{ paramDefine.name }}
</nz-form-label>
<nz-form-control
*ngIf="paramDefine.type === 'textarea'"
nzSpan="8"
[nzErrorTip]="'validation.required' | i18n"
>
<textarea
nz-input
[(ngModel)]="params[i].value"
[required]="paramDefine.required"
[name]="paramDefine.field"
[id]="paramDefine.field"
[placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
rows="3"
></textarea>
</nz-form-control>
<nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field" <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
>{{ paramDefine.name }} >{{ paramDefine.name }}
</nz-form-label> </nz-form-label>