How to post data using HashMap in retrofit?

与世无争的帅哥 提交于 2019-12-22 08:37:12

问题


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



来源:https://stackoverflow.com/questions/42437688/how-to-post-data-using-hashmap-in-retrofit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!