看看MultipartTypedOutput.我不认为有内置支持,所以你必须自己构建或编写转换器.
在您的服务界面:
@POST("/url")
Response uploadUserIds(@Body MultipartTypedOutput listMultipartOutput);
在你的来电者:
MultipartTypedOutput mto = new MultipartTypedOutput();
for (String userId : userIds){
mto.addPart("user_ids[]", new TypedString(userId));
}
service.uploadUserIds(mto);
这将构造类似的结果:
Content-Type: multipart/form-data; boundary=49f201f1-7379-4390-9ea5-97d74e78bb63
Content-Length: 820
--49f201f1-7379-4390-9ea5-97d74e78bb63
Content-Disposition: form-data; name="name"
Content-Type: text/plain; charset=UTF-8
Content-Length: 10
Content-Transfer-Encoding: binary
yourString
--49f201f1-7379-4390-9ea5-97d74e78bb63
Content-Disposition: form-data; name="name"
Content-Type: text/plain; charset=UTF-8
Content-Length: 10
Content-Transfer-Encoding: binary
yourString
--49f201f1-7379-4390-9ea5-97d74e78bb63
Content-Disposition: form-data; name="name"
Content-Type: text/plain; charset=UTF-8
Content-Length: 10
Content-Transfer-Encoding: binary
yourString
--49f201f1-7379-4390-9ea5-97d74e78bb63
Content-Disposition: form-data; name="name"
Content-Type: text/plain; charset=UTF-8
Content-Length: 10
Content-Transfer-Encoding: binary
yourString
--49f201f1-7379-4390-9ea5-97d74e78bb63--