@Test
public void periodicOrganizationTest() throws Exception {
List<PositionRank> ranks = positionRankRepo.findAll();
List<PositionSequence> seqs = positionSequenceRepo.findAll();
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
File file = new File("path");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(new FileInputStream(file), "UTF-8"));
String str = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
str = str + line;
}
JSONObject jsonObject = new JSONObject(str);
for (int i = 0; i < ranks.size(); i++) {
for (int j = 0; j < seqs.size(); j++) {
jsonObject.put("rankId", ranks.get(i).getId());
jsonObject.put("sequenceId", seqs.get(j).getId());
if (j == 0) {
System.out.println(jsonObject.toString());
}
StringEntity stringEntity = new StringEntity(
jsonObject.toString(), "UTF-8");
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
System.out.println(EntityUtils.toString(response.getEntity()));
}
}
}
运用HttpClient多次发送不同json请求进行测试
最新推荐文章于 2024-07-18 02:59:17 发布