I have a very strange problem.
I am using Java to simulate login to the academic Affairs Office website.
but when I proceed to the last step of the GET login interface
I have heard before that the sessionid of cookie obtained by httpClient is invalid
the sessionid obtained with chrome can be used.
however, sessionid that is not valid in eclipse can also be used in chrome.
solve.
//
CookieStore cookieStore = new BasicCookieStore();
HttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
// GET
HttpGet httpget = new HttpGet(loginUrl);
// response
HttpResponse response = httpClient.execute(httpget);
ResponseHandler<String> handler = new BasicResponseHandler();
String body = handler.handleResponse(response);
// cookie
String JSESSIONID = null;
String cookie_user = null;
String result = null;
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); iPP) {
if (cookies.get(i).getName().equals("JSESSIONID")) {
JSESSIONID = cookies.get(i).getValue();
}
if (cookies.get(i).getName().equals("cookie_user")) {
cookie_user = cookies.get(i).getValue();
}
}
if (cookie_user != null) {
result = JSESSIONID;
}
System.out.println("cookie"+cookies.size());
System.out.println("Cookie:"+cookies.toString());
String myCookie=cookies.get(0).getName()+"="+cookies.get(0).getValue()+"; "+cookies.get(1).getName()+"="+cookies.get(1).getValue();
System.out.println(myCookie);
System.out.println("JSESSIONID:"+JSESSIONID);
// GET
HttpGet httpget2 = new HttpGet(dataUrl);
httpget2.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpget2.setHeader("Accept-Encoding", "gzip, deflate, br");
httpget2.setHeader("Accept-Language", "en-US,en;q=0.9,zh;q=0.8,zh-CN;q=0.7");
httpget2.setHeader("Cache-Control", "max-age=0");
httpget2.setHeader("Connection", "keep-alive");
//httpget2.setHeader("Cookie", "JSESSIONID="+JSESSIONID+" SLBMARKN=DDABBAKM");
httpget2.setHeader("Cookie", "JSESSIONID=08vfh9fTvRx55LQchJNB6lhmyw5pJnJ1B4CWQRwqFxTh87wz7Ypv!587741956; SLBMARKN=DDABBAKM");//chromecookie
httpget2.setHeader("Host", "zhjw.neu.edu.cn");
httpget2.setHeader("Referer", "https://zhjw.neu.edu.cn/ACTIONLOGON.APPPROCESS?mode=1&applicant=ACTIONQUERYSTUDENTSCHEDULEBYSELF");
httpget2.setHeader("Upgrade-Insecure-Requests", "1");
httpget2.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36");