!3 feat: http采集功能中增加post的body和content-type

* 增加http post内容
This commit is contained in:
random-chat
2022-02-12 08:58:49 +00:00
committed by tomsun28
parent 5556ec1d0c
commit ef0ba111cc
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.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils;
import javax.net.ssl.SSLException;
import java.io.IOException;
@@ -296,6 +298,9 @@ public class HttpCollectImpl extends AbstractCollect {
log.error("not support the http method: {}.", httpProtocol.getMethod());
return null;
}
String contentType = null;
// params
Map<String, String> params = httpProtocol.getParams();
if (params != null && !params.isEmpty()) {
@@ -303,6 +308,7 @@ public class HttpCollectImpl extends AbstractCollect {
requestBuilder.addParameter(param.getKey(), param.getValue());
}
}
// headers
Map<String, String> headers = httpProtocol.getHeaders();
if (headers != null && !headers.isEmpty()) {
@@ -332,7 +338,11 @@ public class HttpCollectImpl extends AbstractCollect {
String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken();
requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value);
}
// todo 处理请求内容 body 暂不支持body
// 请求内容会覆盖post协议的params
if(StringUtils.hasLength(httpProtocol.getPayload())){
requestBuilder.setEntity(new StringEntity(httpProtocol.getPayload(),"UTF-8"));
}
// uri
if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) {