在 Retrofit2 的单个请求中使用 @FieldMap 和 @Part 得到 java.lang.IllegalArgumentException: only one encoding annotation is allowed.for 方法 [英] Using @FieldMap and @Part in single request in Retrofit2 gets java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method

查看:61
本文介绍了在 Retrofit2 的单个请求中使用 @FieldMap 和 @Part 得到 java.lang.IllegalArgumentException: only one encoding annotation is allowed.for 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能看起来与之前的问题相似,但实际上没有人回答我的问题.我需要使用 Retrofit2 在一个请求中发布多个字段和多个图像,但出现此错误

This might seem similar to earlier questions but none actually answers my question. I need to Post multiple fields and multiple images in one request using retrofit2 and i'm getting this error

java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method xxx

我正在使用

@Multipart
@FormUrlEncoded

因为@Field 需要@FormUrlEncoded 而@Part 需要@Multipart.更合乎逻辑的做法是删除 @FormUrlEncoded 注释,但我如何从那里开始.现在的问题是我如何完成在单个请求中发送我的帖子的任务.

since @Field requires @FormUrlEncoded and @Part requires @Multipart. the more logical thing to do is to remove the @FormUrlEncoded annotation, but how do i go from there. Now the question is how do i go about the task to achieve sending my post in a single request.

这是界面

@Multipart
@FormUrlEncoded
@POST("upload")
Call<ResponseBody> uploadPost(@FieldMap Map<String, String> map,
                       @Part MultipartBody.Part image1,
                       @Part MultipartBody.Part image2,
                       @Part MultipartBody.Part image3);

推荐答案

@Multipart
@POST("upload")
Call<ResponseBody> uploadPost(
        @PartMap() Map<String, RequestBody> descriptions,
        @Part List<MultipartBody.Part> images);

使用这个界面.

这篇关于在 Retrofit2 的单个请求中使用 @FieldMap 和 @Part 得到 java.lang.IllegalArgumentException: only one encoding annotation is allowed.for 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆