拿cookie
//带request payload数据登录获取cookie
String cookie="";
String url="http://127.0.0.1:8080";
HttpPost httpPost=new HttpPost(url);
CloseableHttpClient httpClient= HttpClients.createDefault();
JSONObject jsonObject=new JSONObject();
jsonObject.put("","");
StringEntity stringEntity=new StringEntity((JSONObject.toJSONString(jsonObject)),"application/json","utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpResponse closeableHttpResponse=httpClient.execute(httpPost);
Header[] headers=closeableHttpResponse.getHeaders("Cookies");
Pattern pattern=Pattern.compile("cookie(.*)");
Matcher matcher=pattern.matcher(headers[0].toString());
if(matcher.find()){
cookie=matcher.group(0);
}
抓取页面的数据,返回的类型为json
String url1="";
HttpPost httpPost1=new HttpPost(url);
httpPost1.addHeader("Cookie",cookie);
JSONObject jsonObject1=new JSONObject();
jsonObject1.put("",""); //请求参数
StringEntity stringEntity1=new StringEntity((JSONObject.toJSONString(jsonObject1)),"application/json","utf-8");
httpPost1.setEntity(stringEntity1);
CloseableHttpResponse closeableHttpResponse1=httpClient.execute(httpPost1);
HttpEntity httpEntity=closeableHttpResponse1.getEntity();
InputStream inputStream=httpEntity.getContent();
BufferedReader in=new BufferedReader(new InputStreamReader(inputStream));
JSONObject responseData= JSON.parseObject(in.readLine());
JSONArray jsonArray=responseData.getJSONArray("data"); //获取的json数组



