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,

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 和 stringdata 值。如何使用一个 HTTP Post 请求发送多个 ID?

4

1 回答 1

0

它只获取最后一个,因为 http 参数必须是唯一的。您可以以编程方式将名称更改为 id1、id2 等,然后在服务器端遍历它们。在这种情况下,我个人会将数据作为 XML 发送。

于 2013-02-17T07:31:34.013 回答