2013-02-17 59 views
0
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
nameValuePairs.add(new BasicNameValuePair("id", "12345")); 
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient 我想补充更多的id和stringdatas,安卓:发送HTTP POST请求并提供多个值Web服务器

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
nameValuePairs.add(new BasicNameValuePair("id", "12345")); 
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
nameValuePairs.add(new BasicNameValuePair("id", "12348")); 
nameValuePairs.add(new BasicNameValuePair("stringdata", "wassup")); 
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

当我尝试上面的代码,服务器只获得最后的ID和字符串数据值。我如何使用一个HTTP发布请求发送多个ID?

+0

你可以得到任何解决方案,因为我要求我有id,stringdata等ArrayList,我想发布这个所有arralist数据单连接 – PankajAndroid 2013-11-18 04:36:20

回答

0

由于http参数必须是唯一的,它只会获得最后一个。你可以通过编程方式将名称更改为id1,id2等,然后遍历服务器端。在这种情况下,我会以XML格式发送数据。

+0

没有。 HTTP参数不必是唯一的。 – sparkymat 2016-06-02 23:37:23