TestUtil.java
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.glsk.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class TestUtil {
public static void main(String[] args) throws Exception {
// 1. 准备主题数组(与之前生成的数组一致)
String[] topicCombinations = {
"安利卖点,操作倾向",
"市场涨跌,网感词语",
"基金净值,市场涨跌,操作倾向",
"安利卖点,网感词语,基金净值",
"操作倾向,市场涨跌,安利卖点,网感词语",
"基金净值,安利卖点,操作倾向,市场涨跌",
"网感词语,基金净值,市场涨跌,操作倾向,安利卖点",
"市场涨跌,操作倾向,网感词语,基金净值",
"安利卖点,基金净值",
"操作倾向,网感词语",
"基金净值,操作倾向,安利卖点",
"网感词语,市场涨跌,基金净值",
"安利卖点,市场涨跌,操作倾向,网感词语",
"基金净值,网感词语,操作倾向,市场涨跌",
"市场涨跌,基金净值,安利卖点,操作倾向,网感词语",
"操作倾向,安利卖点",
"网感词语,安利卖点,市场涨跌",
"基金净值,市场涨跌",
"操作倾向,基金净值,网感词语,安利卖点",
"安利卖点,操作倾向,基金净值,市场涨跌,网感词语"
};
String postDate = "2025-11-19";
// 2. 创建HttpClient
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
// 3. 构建请求
String baseUrl = "http://localhost:8090/api/ai/common/post_merge_summary";
for (String theme : topicCombinations) {
String url = baseUrl + "?post_date=" + URLEncoder.encode(postDate, StandardCharsets.UTF_8.name())
+ "&themes=" + theme;
// 6. 创建POST请求(参数在URL中)
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/json; charset=UTF-8");
// 7. 执行请求
try (CloseableHttpResponse response = httpClient.execute(request)) {
// 8. 处理响应
int statusCode = response.getStatusLine().getStatusCode();
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
System.out.println("Status: " + statusCode);
System.out.println("Response: " + responseBody);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
httpClient.close();
}
}