feat: 新增copilot所需接口

This commit is contained in:
junjun
2024-07-08 13:23:48 +08:00
parent d27770b858
commit 2e1718c350
2 changed files with 40 additions and 4 deletions

View File

@@ -32,10 +32,7 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import static io.dataease.result.ResultCode.SYSTEM_INNER_ERROR;
@@ -222,6 +219,41 @@ public class HttpClientUtil {
}
}
public static HttpResponse postWithHeaders(String url, String json, HttpClientConfig config) {
CloseableHttpClient httpClient = null;
try {
httpClient = buildHttpClient(url);
HttpPost httpPost = new HttpPost(url);
if (config == null) {
config = new HttpClientConfig();
}
httpPost.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader();
for (String key : header.keySet()) {
httpPost.addHeader(key, header.get(key));
}
EntityBuilder entityBuilder = EntityBuilder.create();
entityBuilder.setText(json);
entityBuilder.setContentType(ContentType.APPLICATION_JSON);
HttpEntity requestEntity = entityBuilder.build();
httpPost.setEntity(requestEntity);
HttpResponse response = httpClient.execute(httpPost);
return response;
} catch (Exception e) {
logger.error("HttpClient查询失败", e);
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (Exception e) {
logger.error("HttpClient关闭连接失败", e);
}
}
}
public static String put(String url, String json, HttpClientConfig config) {
CloseableHttpClient httpClient = null;
try {