聚合全网技术文章,根据你的阅读喜好进行个性推荐
开源之夏第三届火热来袭,高校学生参与赢万元奖金!>>>
HttpComponents 改动相当大
新版的不知道咋个设置 cookie
@红薯
ok 已经找到 .
http://hc.apache.org/httpcomponents-client-4.3.x/tutorial/html/statemgmt.html#d5e563
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(); }
ok 已经找到 .
http://hc.apache.org/httpcomponents-client-4.3.x/tutorial/html/statemgmt.html#d5e563