标签:android shm ima eth src span dia ted alt
官方网站 https://www.androidhive.info/2014/05/android-working-with-volley-library-1/
/*
* 使用Volley提交get请求
*/
/*
1. 创建请求队列对象(一次)
2. 创建请求对象StringRequest
3. 将请求添加到队列中
*/
public void testVolleyGet(View v) {
final ProgressDialog dialog = ProgressDialog.show(this, null, "正在请求中...");
//创建请求对象StringRequest
String path = et_network_url.getText().toString()+"?name=Tom5&age=15";
StringRequest request = new StringRequest(path, new Response.Listener<String>() {
@Override
public void onResponse(String response) {//在主线程执行
et_network_result.setText(response);
dialog.dismiss();
}
}, null);
//将请求添加到队列中
queue.add(request);
}
/*
* 使用Volley提交post请求
*/
public void testVolleyPost(View v) {
final ProgressDialog dialog = ProgressDialog.show(this, null, "正在请求中...");
//创建请求对象StringRequest
String path = et_network_url.getText().toString();
StringRequest request = new StringRequest(Method.POST, path, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
et_network_result.setText(response);
dialog.dismiss();
}
}, null){
//重写此方法返回参数的map作为请求体
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String, String>();
map.put("name", "Tom6");
map.put("age", "16");
return map;
}
};
//将请求添加到队列中
queue.add(request);
}
标签:android shm ima eth src span dia ted alt
原文地址:https://www.cnblogs.com/znsongshu/p/9346445.html