URL模拟登陆出现的小问题(新手)

来源:互联网 发布:儿童电脑画图软件 编辑:程序博客网 时间:2024/05/21 09:27

0x00

List<NameValuePair> params = new ArrayList<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对象


0 0