public void testToToken() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:8081/user/login");
JSONObject jsonObject = new JSONObject();
FileWriter fileWriter = new FileWriter("F:\\help\\redis\\token.txt");
Long phone = 13688668889L;
for (int i = 0; i < 300; i++) {
phone++;
jsonObject.put("phone",phone.toString());
StringEntity stringEntity = new StringEntity(jsonObject.toString());
stringEntity.setContentType("application/json");
stringEntity.setContentEncoding("UTF-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String string = EntityUtils.toString(entity);
ObjectMapper mapper = new ObjectMapper();
HashMap hashMap = mapper.readValue(string, HashMap.class);
String o = (String) hashMap.get("data");
System.out.println(o);
fileWriter.write(o);
fileWriter.write("\n");
}
fileWriter.close();
// jsonObject.put("phone","13424383868");
// StringEntity stringEntity = new StringEntity(jsonObject.toString()); //StringEntity字符串数据封装为HTTP请求的实体(body)
// stringEntity.setContentType("application/json");
// stringEntity.setContentEncoding("UTF-8");
// httpPost.setEntity(stringEntity);
// //发送请求
// CloseableHttpResponse response = httpClient.execute(httpPost);
// HttpEntity entity = response.getEntity();
// String string = EntityUtils.toString(entity);
// ObjectMapper mapper = new ObjectMapper();
// HashMap hashMap = mapper.readValue(string, HashMap.class);
// String o = (String) hashMap.get("data");
// System.out.println(o);
}
用HttpClient去获得多个Token
最新推荐文章于 2024-10-06 20:16:20 发布