我想在 HttpURLConnection android 中 post 数组参数

I want to post array param in HttpURLConnection android

我刚开始开发 Android 应用程序,我想在我的应用程序中 post 参数采用以下格式:

user_id=12&task_id=100&user_ids=["91","92"]

我无法发送数组格式的 user_ids。我在 Rails API.

中收到 user_ids 作为字符串

我正在使用 HttpURLConnection,在我的 writer.write() 中,我将我的 post 参数传递为

writer.write("user_id="+id+"&task_id="+tid+"&user_ids="+["91","92"]+");

请帮忙。

如果有人面临同样的问题,我找到了解决方法。 您需要在字符串中添加数组

1.步骤 1

Create a final ArrayList<String> SelectedTagIds = new ArrayList<String>();

并使用

添加数组项
SelectedTagIds.add("One");
SelectedTagIds.add("Two");
...

2。第 2 步

转换

SelectedTagIds.toString();

3。第 3 步

通过将字符串替换为

来格式化字符串
SelectedTagIds.replace("[","").replace("]","").replaceAll("\s","").trim();

4 步骤 4

最后post将String传给服务器(我用HttpURLConnectionpost我的数据传给服务器),在服务器代码中,将接收到的SelectedTagIds转成Array,循环相应实现你想要的结果。