android volley http请求框架

简介: 2015年11月6日 14:35:19 注意:  1.安卓官方的volley在google的codesource上, 在github上有他的镜像android-volley, 并解决了官方的一部分bug 2.

2015年11月6日 14:35:19

注意: 

1.安卓官方的volley在google的codesource上, 在github上有他的镜像android-volley, 并解决了官方的一部分bug

2.github上的镜像clone下来后, 用android studio打开(file->open...->dir/of/android-volley)时会自动构建, 并生成相应的jar和aar

3.在自己的项目中使用volley.jar时, 不用再引入apache的httpclient或者httpcore (话外, httpclient 包含httpcore)

测试代码:

 1 protected void onCreate(Bundle savedInstanceState)
 2     {
 3         super.onCreate(savedInstanceState);
 4         setContentView(R.layout.activity_main);
 5 
 6         String url = "http://www.zhangzhibin.com/test/index/androidtest";
 7         RequestQueue mqueue = Volley.newRequestQueue(this);
 8 
 9         StringRequest strRequest = new StringRequest(
10                 url,
11                 new Response.Listener<String>()
12                 {
13                     @Override
14                     public void onResponse(String response)
15                     {
16                         Log.d("TAG", response);
17                     }
18                 },
19 
20                 new Response.ErrorListener()
21                 {
22                     @Override
23                     public void onErrorResponse(VolleyError error)
24                     {
25                         Log.d("TAG", "onErrorResponse "+error.getMessage(), error);
26                     }
27 
28                 }
29         );
30 
31         mqueue.add(strRequest);
32 
33         JsonArrayRequest jsonArrRequest = new JsonArrayRequest(
34                 url,
35                 new Response.Listener<JSONArray>()
36                 {
37                     public void onResponse(JSONArray response)
38                     {
39                         Log.d("TAG", response.toString());
40                     }
41                 },
42                 new Response.ErrorListener()
43                 {
44                     public void onErrorResponse (VolleyError error)
45                     {
46                         Log.d("TAG", "volley error ==> "+error.getMessage(), error);
47                     }
48                 }
49         );
50 
51         mqueue.add(jsonArrRequest);
52 
53         JsonObjectRequest jsonObjRequest = new JsonObjectRequest(
54                 url,
55                 new Response.Listener<JSONObject>()
56                 {
57                     public void onResponse(JSONObject response)
58                     {
59                         Log.d("TAG", response.toString());
60                     }
61                 },
62                 new Response.ErrorListener()
63                 {
64                     public void onErrorResponse (VolleyError error)
65                     {
66                         Log.d("TAG", "volley error ==> "+error.getMessage(), error);
67                     }
68                 }
69         );
70 
71         mqueue.add(jsonObjRequest);
72     }

参考: 

使用中文简介: http://www.kwstu.com/ArticleView/kwstu_20144118313429

github: https://github.com/mcxiaoke/android-volley

jar/aar: http://blog.csdn.net/qiujuer/article/details/39754517

 

目录
相关文章
|
14天前
|
Java
java原生发送http请求
java原生发送http请求
|
21天前
|
网络协议 Linux iOS开发
推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
46 1
|
1月前
|
编解码 测试技术 索引
性能工具之 Jmeter 使用 HTTP 请求编写 HLS 脚本
在我们简要介绍了 HLS 协议的基础知识,接下来我们详细介绍一种使用 Jmeter 编写压测 HLS 协议脚本的方法。
72 1
性能工具之 Jmeter 使用 HTTP 请求编写 HLS 脚本
|
1月前
|
JSON 数据格式
第三方系统或者工具通过 HTTP 请求发送给 ABAP 系统的数据,应该如何解析试读版
第三方系统或者工具通过 HTTP 请求发送给 ABAP 系统的数据,应该如何解析试读版
27 0
|
3天前
|
安全 Java 网络安全
Servlet 教程 之 Servlet 客户端 HTTP 请求 2
Servlet教程介绍了如何在Servlet中处理HTTP请求,包括获取Cookie、头信息、参数、Session等。方法如:`getCookies()`、`getAttributeNames()`、`getHeaderNames()`、`getParameterNames()`等。还能获取身份验证类型、字符编码、MIME类型、请求方法、远程用户信息、URL路径、安全通道状态以及请求内容长度等。此外,可通过`getSession()`创建或获取Session,并以`Map`形式获取参数。
19 8
|
6天前
|
安全 网络安全 开发工具
对象存储oss使用问题之flutter使用http库进行post请求文件上传返回400如何解决
《对象存储OSS操作报错合集》精选了用户在使用阿里云对象存储服务(OSS)过程中出现的各种常见及疑难报错情况,包括但不限于权限问题、上传下载异常、Bucket配置错误、网络连接问题、跨域资源共享(CORS)设定错误、数据一致性问题以及API调用失败等场景。为用户降低故障排查时间,确保OSS服务的稳定运行与高效利用。
20 1
|
7天前
|
网络协议 安全 API
Android网络和数据交互: 什么是HTTP和HTTPS?在Android中如何进行网络请求?
HTTP和HTTPS是网络数据传输协议,HTTP基于TCP/IP,简单快速,HTTPS则是加密的HTTP,确保数据安全。在Android中,过去常用HttpURLConnection和HttpClient,但HttpClient自Android 6.0起被移除。现在推荐使用支持TLS、流式上传下载、超时配置等特性的HttpsURLConnection进行网络请求。
8 0
|
25天前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
21 5
|
1月前
|
JSON 前端开发 数据格式
糊涂工具类真是场景下请求http接口的案例
糊涂工具类真是场景下请求http接口的案例
21 0
|
1月前
|
数据采集 缓存 前端开发
http和https请求服务器的时候在请求头部分都带什么到服务器呢?
HTTP和HTTPS请求头基本结构相似,HTTPS多了一层SSL/TLS加密。常见请求头如Accept(指定内容类型)、Authorization(身份验证)、Cookie(会话跟踪)、User-Agent(标识用户代理)等。HTTPS特有的头包括Upgrade-Insecure-Requests(升级到HTTPS)、Strict-Transport-Security(强制使用HTTPS)、Sec-Fetch-*(安全策略)和X-Content-Type-Options、X-Frame-Options等(增强安全性)。实际应用中,请求头会根据需求和安全策略变化。
20 0