Can you please explain how to post data using hashmap in retrofit2 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is what I post
@FormUrlEncoded
@POST("getProfile")
Call<YourResponseObject> getProfile(@FieldMap HashMap<String, String> data);
And the HashMap
HashMap<String, String> map = new HashMap<>();
map.put("token", "yourtoken");
map.put("yourvariable", "yourvariable");
回答2:
From Retrofit2 documentation check FieldMap for more details You need to create your interface
public interface YourPostService {
@FormUrlEncoded
@POST("/myEndpoint")
Call<YourResponseClass> postData(@FieldMap Map<String, String> fields);
}
and after this is easy to call and use it