【发布时间】:2016-06-08 09:36:14
【问题描述】:
我需要通过 Retrofit 向服务器发送一个列表/一个整数值数组(通过 POST) 我是这样做的:
@FormUrlEncoded
@POST("/profile/searchProfile")
Call<ResponseBody> postSearchProfile(
@Field("age") List<Integer> age
};
然后这样发送:
ArrayList<Integer> ages = new ArrayList<>();
ages.add(20);
ages.add(30);
ISearchProfilePost iSearchProfile = gsonServerAPIRetrofit.create(ISearchProfilePost.class);
Call<ResponseBody> call = iSearchProfile.postSearchProfile(
ages
);
问题是,到达服务器的值不是逗号分隔的。所以那里的值就像 age: 2030 而不是 age: 20, 30。
我正在阅读(例如这里https://stackoverflow.com/a/37254442/1565635),有些人通过像数组一样使用 [] 写入参数取得了成功,但这只会导致名为 age[] : 2030 的参数。 我还尝试使用数组以及带字符串的列表。同样的问题。一切都直接出现在一个条目中。
那我该怎么办?
【问题讨论】:
-
也检查那个解决方案,我正在关注 Gson 来解决类似的问题stackoverflow.com/a/64621637/12228284
标签: android http-post retrofit