Android:NameValuePair用法

下面讲一下Android中NameValuePair的用法
定义了一个list,该list的数据类型是NameValuePair(简单名称值对节点类型),这个代码多处用于Java像url发送Post请求。在发送post请求时用该list来存放参数。
发送请求的大致过程如下:

String url="http://www.baidu.com";

HttpPost httppost=new HttpPost(url); //建立HttpPost对象

List<NameValuePair> params=new ArrayList<NameValuePair>();
//建立一个NameValuePair数组,用于存储欲传送的参数

params.add(new BasicNameValuePair("pwd","2544"));
//添加参数

httppost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
//设置编码

HttpResponse response=new DefaultHttpClient().execute(httppost);
//发送Post,并返回一个HttpResponse对象

猜你喜欢

转载自jinggege503.iteye.com/blog/2307451
今日推荐