怎么设置 cookie 呢 ?

sjack 发布于 2013/10/10 15:59
阅读 2K+
收藏 0

Linux基金会开源软件大学开源技术公开课即将上线,Kubernetes1.19实战讲解!>>>

HttpComponents  改动相当大

新版的不知道咋个设置 cookie


@红薯  

加载中
0
sjack
sjack
public static void main(String[] args) throws Exception {
		String url = "http://localhost/wp/";
		HttpPost get = new HttpPost(url);

		CookieStore cookieStore = new BasicCookieStore();
		// Populate cookies if needed
		BasicClientCookie cookie = new BasicClientCookie("wordpress_1233097993469c07c80a9cb529880b71", "admin%7C1382592376%7Cfb75237b2f52e29332627a77575438a2");
		cookie.setVersion(0);
		cookie.setDomain("localhost");
		cookie.setPath("/");
		cookieStore.addCookie(cookie);
		// Set the store
		CloseableHttpClient client = HttpClients.custom()
		        .setDefaultCookieStore(cookieStore)
		        .build();
		
		HttpResponse resp = client.execute(get);

		HttpEntity enti = resp.getEntity();
		InputStream is = enti.getContent();
		BufferedReader in = new BufferedReader(new InputStreamReader(is));
		StringBuffer buffer = new StringBuffer();
		System.out.println(EntityUtils.toString(enti));
		
		
		get.abort();
		client.close();

	}
0
鶴嘯九天
鶴嘯九天

然而没有卵用!!!!!!!!!!!!!!!!!!!!!!!

sjack
sjack
!
返回顶部
顶部