1)用于cookie的AS,请参阅exapmle:
httpcomponents-客户4.1.3 \例子\组织\阿帕奇\ HTTP \例子\客户\ ClientCustomContext.java
主要代码:
HttpClient httpclient = new DefaultHttpClient();
try {
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}2)您可以从响应中获得所需的一切:
HttpEntity entity = response.getEntity();
entity.getContent()只需阅读以下示例:
httpcomponents-客户4.1.3 \例子\组织\阿帕奇\ HTTP \例子\客户端
httpcomponents-client-4.1.3-bin.zip的下载,从website下载。