2013-02-17 65 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