gpt4 book ai didi

java - 如何在 HTTPPOST 请求中将 ArrayList 作为 UrlEncodedFormEntity 发送?

转载 作者:行者123 更新时间:2023-11-30 02:31:43 46 4
gpt4 key购买 nike

您好,我正在尝试将 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:我想发表评论而不是回答,因为我不知道它是否能如你所愿。

关于java - 如何在 HTTPPOST 请求中将 ArrayList<Integer> 作为 UrlEncodedFormEntity 发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27236356/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com