簡體   English   中英

如何發送ArrayList <Integer> 作為HTTPPOST請求中的UrlEncodedFormEntity?

[英]How to send ArrayList<Integer> as UrlEncodedFormEntity in HTTPPOST request?

嗨,我正在嘗試將ArrayList作為POST請求的參數從我的Android應用發送到服務器。 到目前為止,我有以下代碼:

HttpResponse response;

        List<NameValuePair> postParams = new ArrayList<NameValuePair>(2);
        postParams.add(new BasicNameValuePair("post[text]", text));
        postParams.add(new BasicNameValuePair("post[common_comments]", String.valueOf(commonComments));
        postParams.add(new BasicNameValuePair("post[wall_ids]", wallIds);

        UrlEncodedFormEntity encodedParams;
        try {
            encodedParams = new UrlEncodedFormEntity(postParams);
            post.setEntity(encodedParams);
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }

但是BasicNameValuePair僅接收String作為值。 有什么方法可以將ArrayList作為post [wall_ids]的值發送?

提前致謝。

布宜諾斯艾利斯卡拉。
我不知道您是否解決了這個問題(兩個月是很多時間)...但是也許可以為您提供幫助:

 for(String wallyID: wallyIDs)
      postParams.add(new BasicNameValuePair("extraFields[wallyIDs][]", wallyID));

如果您想使用拉丁字符(在服務器上忘記了),則最好使用“ utf 8”格式,例如:

  HttpClient httpclient = new DefaultHttpClient(); 
  HttpPost httppost = new HttpPost(url);
  httppost.setEntity(new UrlEncodedFormEntity(postParams, HTTP.UTF_8));

我有一個關於List構造函數的問題...為什么要使用2作為它的參數?

PS:我想提出一個意見,而不是一個答案,因為我不知道它是否可以按您的意願工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM