okhttp
2016-06-14 10:12
459 查看
jar包
https://yunpan.cn/cRcDaaJbfJgdd 访问密码 ca91
get请求
//返回二进制字节数组
//byte[] bytes = response.body().bytes();
//返回流inputStream
//InputStream is = response.body().byteStream();
post请求
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(); } });
相关文章推荐
- HOT软件市场v2.0安卓版
- HTTPS那些事 用java实现HTTPS工作原理
- HttpClient和HttpUrlConnection的请求网路
- Android官方开发文档Training系列课程中文版:网络操作之XML解析
- tcpdump抓包分析TCP三次握手过程
- Struts1.3 HTTP Status 500 No action config found for the specified url
- Android网络框架Volley
- 浏览器被定向至http://hao.169x.cn/?v=108
- Linux TCP队列相关参数的总结
- 【Linux C/C++】 第04讲 多进程TCP传输文件
- 在C#中带连接超时功能的TcpClient类
- HTTP协议详解(转载)
- 初识HTTP 1.1与HTTP 1.0
- OSI参考模型及TCP/IP参考模型
- Anroid搭建一个局域网Http服务器
- jiaocheng https://github.com/CarpenterLee/JCFInternals
- Android学习-使用Async-Http实现图片压缩并上传功能
- Startssl 现在就启用 HTTPS,免费的!
- 网络人远程监控软件(Netman旗舰版) v2.311官方版
- 香港服务器租用及香港服务器托管方法