Android 工具类httpClient
来源:互联网 发布:九次方大数据 上市 编辑:程序博客网 时间:2024/05/17 23:21
jar包下载
httppost
private static void Httppost() {//创建HttpClientBuilder HttpClientBuilder newBuilder = HttpClientBuilder.create(); CloseableHttpClient newClient = newBuilder.build(); //接口地址String url="";//httppostHttpPost newHttppost=new HttpPost(url);//默认配置postnewHttppost.setConfig(RequestConfig.DEFAULT);//post数据String postString="";//post实体StringEntity entity=new StringEntity(postString,"UTF-8");try { newHttppost.setEntity(entity); //执行httppost请求 HttpResponse httpResponse=newClient.execute(newHttppost); //获取响应实体 HttpEntity httpEntity=httpResponse.getEntity(); //响应状态 System.out.println("StatusLine: " +httpResponse.getStatusLine()); if (httpEntity != null) { System.out.println("contentEncoding:" + httpEntity.getContentEncoding()); System.out.println("response content:" + EntityUtils.toString(httpEntity)); } } catch (IOException e) { e.printStackTrace(); } finally { try { //关闭流并释放资源 newClient.close(); } catch (IOException e) { e.printStackTrace(); } } }
httpget
private static void HttpGet() {//创建Client HttpClientBuilder newBuilder=HttpClientBuilder.create(); CloseableHttpClient newClient=newBuilder.build(); //Httpget HttpGet newHttpget=new HttpGet("http://hq.sinajs.cn/list=sh601006"); System.out.println("RequestLint: " + newHttpget.getRequestLine()); try { //执行get请求 HttpResponse httpResponse=newClient.execute(newHttpget); //获取响应实体 HttpEntity httpEntity=httpResponse.getEntity(); //响应状态 System.out.println("StatusLine: " +httpResponse.getStatusLine()); if (httpEntity != null) { System.out.println("contentEncoding:" + httpEntity.getContentEncoding()); //将返回实体字符串输出 System.out.println("response content:" + EntityUtils.toString(httpEntity)); } } catch (IOException e) { e.printStackTrace(); } finally { try { //关闭流并释放资源 newClient.close(); } catch (IOException e) { e.printStackTrace(); } } }/**RequestLint: GET http://hq.sinajs.cn/list=sh601006 HTTP/1.1StatusLine: HTTP/1.1 200 OKcontentEncoding:nullresponse content:var hq_str_sh601006="..."*/
传输实体
- UrlEncodedFormEntity()
List<NameValuePair> pairs = new ArrayList<NameValuePair>(); NameValuePair pair1 = new BasicNameValuePair("supervisor", supervisorEt.getEditableText().toString()); pairs.add(pair1); httpPost.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
- StringEntity()
httpPost.setEntity(new StringEntity(postData.toString(), HTTP.UTF_8));
0 0
- Android:HttpClient工具类
- Android 工具类httpClient
- Android 浅谈HttpClient工具类
- Android 浅谈HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android开发实现HttpClient工具类
- Android中采用HttpClient的工具类
- Android开发实现HttpClient工具类
- HttpClient 操作工具类---
- httpclient工具类java
- httpclient工具类java
- HttpClient工具类
- oracle从字符串中提取数字
- 转:mysql处理海量数据时的一些优化查询速度方法
- easyui 根据rowIndex行号 获取该行的值
- WEB SERVICE PROJECT实例(XFire、接口开发)
- 第4周项目3-单链表应用(2)
- Android 工具类httpClient
- 第四周-项目五 猴子选大王
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- 移动端前端常见的触摸相关事件touch、tap、swipe等整理
- 虚拟机安装CentOS 7后无法上网问题解决办法(NAT 模式)
- IOS中UITableView使用总结
- java 多线程:原子性与可视性
- Python语言总结
- Nginx负载均衡配置实例详解