Android之Retrofit报错Form-encoded method must contain at least one @Field.

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LVXIANGAN/article/details/82026808

今天使用retrofit的时候,接口参数写成这样报错:Form-encoded method must contain at least one @Field....

@FormUrlEncoded
@POST("/appApi/client/familyInfo/insertFamilyInfo")
Observable<BaseRespModel> insertFamilyInfo (
        @QueryMap Map<String,String> paramsMap
);

经过了解,原来post请求,不能用@Query 或@QueryMap 参数,必须要使用@FieldMap,改成这样:

@FormUrlEncoded
@POST("/appApi/client/familyInfo/insertFamilyInfo")
Observable<BaseRespModel> insertFamilyInfo (
        @FieldMap Map<String,String> paramsMap
);

总结:

retrofit使用get请求,少参数使用@Query 注解,多参数使用@QueryMap;

使用post请求,少参数使用@Field 注解,多参数使用@FieldMap。

猜你喜欢

转载自blog.csdn.net/LVXIANGAN/article/details/82026808