【发布时间】:2014-08-30 01:31:32
【问题描述】:
在调用 loginTask 时,我必须发送用户名和密码。现在我尝试用HashMap<String,String> 替换这个List<NameValuePair> 代码,但我做不到。知道我需要知道它们之间的区别。什么时候应该使用 List,什么时候应该使用 HashMap
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("username", params[0]));
list.add(new BasicNameValuePair("password", params[1]));
httppost.setEntity(new UrlEncodedFormEntity(list));
HttpResponse responce = httpclient.execute(httppost);
HttpEntity httpEntity = responce.getEntity();
response = EntityUtils.toString(httpEntity);
【问题讨论】:
-
请解释一下列表和地图@PhamTrung之间的区别
-
@Nepster 哈哈,看看我在评论里给你的链接 :) Geek 的链接也不错。
-
我如何接受 Geek Answer。感谢 PhamTrung 和 Geek