代码如下: get请求服务端,获得服务端返回的cookie
。
public void firefox(String url) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = httpClient.execute(httpget);
StatusLine s = response.getStatusLine();
if (s.getStatusCode() == 200){
Header[] hs = response.getHeaders("Set-Cookie");
for (Header header:hs){
System.out.println(header);
}
} else {
logger.error("访问:"+url+"出错");
}
// HttpEntity httpEntity = response.getEntity();
// String strResult = EntityUtils.toString(httpEntity);
// System.out.println(strResult);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}