android volley http请求框架
生活随笔
收集整理的這篇文章主要介紹了
android volley http请求框架
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
?
總結
以上是生活随笔為你收集整理的android volley http请求框架的全部內容,希望文章能夠幫你解決所遇到的問題。