httpclient请求中 get带cookie

下面是代码

	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)