在使用httpClient的时候,为了模拟另一个已经登录过的用户进行操作。这里进行模拟。
httpClient的包要4.3.3以上。
BasicCookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "已经登录的用户所用的sessionId");
cookie.setDomain("192.168.212.113"); //项目IP
cookie.setPath("/***/"); //JSESSIONID的存储路径
cookieStore.addCookie(cookie);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
final HttpGet requestGET = new HttpGet("http://192.168.212.113:8080/***/index/logout");
HttpResponse res = client.execute(requestGET);
if (res.getStatusLine().getStatusCode() == 200) {
HttpEntity entity2 = res.getEntity();
。
。
。
像上面的那些设置信息在F12里的cookie那都可以看得到。