通过http://blog.csdn.net/ysh06201418/article/details/46443235学习
GET方式请求
//获取请求队列
RequestQueue mQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest("http://www.baidu.com", new Response.Listener<String>() {
public void onResponse(String s) {
Log.d("TAG", s);
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError volleyError) {
Log.d("TAG",volleyError.getMessage(),volleyError);
}
});
mQueue.add(stringRequest);
Post方式请求
//获取请求队列
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, "www.baidu.com", new Response.Listener<String>() {
@Override
public void onResponse(String s) {
Log.e("TAG",s);
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String, String>();
map.put("Phone", "110");
return map;
}
};
requestQueue.add(stringRequest);