下面是代码
public static String getetSendCookie(String url, String cookies) {
String result = "";
CookieStore cookieStore = new BasicCookieStore();
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();
try {
HttpGet httpGet = new HttpGet(url);//这里发送get请求
httpGet.setHeader("Connection","keep-alive");
httpGet.addHeader(new BasicHeader("Cookie", cookies));
// 通过请求对象获取响应对象
HttpResponse response = httpClient.execute(httpGet);
// 判断网络连接状态码是否正常(0--200都数正常)
result = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
本文介绍了一段Java代码,该代码使用HttpClient发起GET请求,并处理Cookie信息。具体包括创建CookieStore,设置HttpClient默认CookieStore,构建HttpGet请求,设置请求头信息如Connection保持和Cookie,执行请求并获取响应实体。
1325

被折叠的 条评论
为什么被折叠?



