okhttp
来源:互联网 发布:音画不同步修正软件 编辑:程序博客网 时间:2024/05/02 04:15
jar包
https://yunpan.cn/cRcDaaJbfJgdd 访问密码 ca91
get请求
//创建okHttpClient对象 OkHttpClient okClient = new OkHttpClient(); //创建一个Request final Request request = new Request.Builder() .url("http://www.quwenlieqi.com/app/v2/api.php?m=102") .build(); //new call Call call = okClient.newCall(request); //请求加入调度 call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { System.out.println("请求失败"); } @Override public void onResponse(final Response response) throws IOException { System.out.println("请求成功"); String htmlStr = response.body().string(); System.out.println(htmlStr);
//返回二进制字节数组
//byte[] bytes = response.body().bytes();
//返回流inputStream
//InputStream is = response.body().byteStream();
} }); }
post请求
// 创建okHttpClient对象 OkHttpClient okClient = new OkHttpClient(); FormEncodingBuilder builder = new FormEncodingBuilder(); // builder.add("cid","27");// builder.add("num","20"); Request request = new Request.Builder() .url(url) .post(builder.build()) .build();// new call Call call = okClient.newCall(request); // 请求加入调度 call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { System.out.println("请求失败"); } @Override public void onResponse(final Response response) throws IOException { System.out.println("请求成功"); //返回字符串 String htmlStr = response.body().string(); System.out.println(htmlStr); //返回二进制字节数组 //byte[] bytes = response.body().bytes(); //返回流inputStream //InputStream is = response.body().byteStream(); } });
0 0
- OkHttp
- okhttp
- OkHttp
- OkHttp
- OkHttp
- okhttp
- OKHTTP
- okhttp
- Okhttp
- okHttp
- OkHttp
- okhttp
- Okhttp
- okhttp
- OkHttp
- okhttp
- okhttp
- okhttp
- 什么是Web静态资源
- ubuntu16.04 安装 eclipse
- 2016系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
- wampserver启动状态是橙色的,即80端口被占用
- 队列的实现(二) 链式队列的实现
- okhttp
- oracle数据库表用序列实现主键自增长
- Quick Start Guide for Using the OpenVPN Access Server Virtual Appliance for the VMWare ESXi Virtuali
- handle的使用
- Flatten Nested List Iterator
- strlen函数的实现
- 干货:解密如何一个月时间使至网站达到权重4
- PostgreSQL初识
- 基于libevent框架搭建http服务器