How to post data using HashMap in retrofit?

2020-02-12 13:31发布

Can you please explain how to post data using hashmap in retrofit2 ?

2条回答
你好瞎i
2楼-- · 2020-02-12 13:46

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");
查看更多
Luminary・发光体
3楼-- · 2020-02-12 14:00

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

查看更多
登录 后发表回答