栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java-apache http客户端用法示例,显示cookie的使用以及从HTTPResponse对象提取响应

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java-apache http客户端用法示例,显示cookie的使用以及从HTTPResponse对象提取响应

1)AS为cookie,请参见示例:

httpcomponents-client-4.1.3 examples org apache http examples
client 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-client-4.1.3-bin.zip的httpcomponents-client-4.1.3
examples org apache http examples
client(可从其网站下载)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570471.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号