Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post data using HashMap in retrofit?

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

like image 734
Akash Ratanpara Avatar asked Feb 24 '17 11:02

Akash Ratanpara


2 Answers

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

like image 37
dario.budimir Avatar answered Oct 01 '22 15:10

dario.budimir


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");
like image 113
Truong Hieu Avatar answered Oct 01 '22 15:10

Truong Hieu