httpClient4.2官方文档研究(4)第3章
?
3.9.每个用户/线程的状态管理
?可以使用一个单独的本地执行上下文,以实现每个用户(或每线程)的状态管理。一个cookie规范注册表和cookie存储在本地范围内定义在默认的设置在HTTP客户端级别的优先级。
用法如下:
HttpClient httpclient = new DefaultHttpClient();// Create a local instance of cookie storeCookieStore cookieStore = new BasicCookieStore();// Create local HTTP contextHttpContext localContext = new BasicHttpContext();// Bind custom cookie store to the local contextlocalContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);HttpGet httpget = new HttpGet("http://www.google.com/"); // Pass local context as a parameterHttpResponse response = httpclient.execute(httpget, localContext);
?
?