您的位置:首页 > 产品设计 > UI/UE

NameValuePair的用法

2016-04-08 00:19 393 查看
定义了一个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对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: