HttpClient使用笔记
2015-11-06 15:37
281 查看
使用版本为4.5.1
常用API:
1.获取网页内容:InputStream in = response.getEntity().getContent()
2.获取状态码:response.getStatusLine().getStatusCode()
3.获取首部字段:Header[] headers = response.getAllHeaders();for(Header header : headers){...},也可以用getHeaders(XXX)方法根据名字单个获取
4.设置连接超时:RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();httpGet.setConfig(requestConfig);
常见问题:
1.关于重定向:用get 的时,如果有重定向,会自动再去访问重定向的内容 。 但用post访问url就不会自动访问重定向的内容。
常用API:
1.获取网页内容:InputStream in = response.getEntity().getContent()
2.获取状态码:response.getStatusLine().getStatusCode()
3.获取首部字段:Header[] headers = response.getAllHeaders();for(Header header : headers){...},也可以用getHeaders(XXX)方法根据名字单个获取
4.设置连接超时:RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();httpGet.setConfig(requestConfig);
常见问题:
1.关于重定向:用get 的时,如果有重定向,会自动再去访问重定向的内容 。 但用post访问url就不会自动访问重定向的内容。
相关文章推荐
- 谷歌热气球4G网络将开始商用 偏僻地区人能上网
- 操作系统与网络实现 之三
- The method getDispatcherType() is undefined for the type HttpServletRequest
- 安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)
- 安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)
- AsyncSocket实现TCP连接
- CentOS 安装httpd
- dfs搜索练习题 http://codeforces.com/problemset/problem/589/J
- php编写TCP服务端和客户端程序
- android中图片的三级cache策略(内存、文件、网络)之二:内存缓存策略
- Android利用Fiddler进行网络数据抓包
- 【网络流】:调查设计、航线调度、项目选择
- PHP http_build_query()函数
- poj 1087 A Plug for UNIX 网络流
- ajax原理和XmlHttpRequest对象
- android volley http请求框架
- 使用HttpURLConnection发送Post/Get请求
- 错误:app Transport Security has blocked a cleartext HTTP......
- JAVA实现HTTP服务器端
- HTTP 长连接和短连接