How to pass Map parameters or object to POST request via Retrofit?

后端 未结 3 1092
花落未央
花落未央 2020-12-14 22:30

I have a problem with passing Map parameters or object to Retrofit POST request.

I follow square, kdubb labs tutorials and this thread and I couldn\'t figure it out.

相关标签:
3条回答
  • 2020-12-14 22:48

    In retrofit 2.0 you have to do this way:

    @FormUrlEncoded
        @POST(Constant.API_Login)
        Call<UserLoginPost> userLogin(@FieldMap Map<String, String> params);
    
    0 讨论(0)
  • 2020-12-14 23:05

    This feature is still not supported by the Retrofit 1.2.2, however you can compile your own version from the master branch with this feature or wait for the next release.

    https://github.com/square/retrofit/pull/390

    Update:

    It's available in Retrofit version 1.5.0 ! (ref Anton Golovin answer)

    0 讨论(0)
  • 2020-12-14 23:07

    Well, now we can implement this thing (version 1.5.0).

    @FormUrlEncoded
    @POST("/oauth/access_token")
    void getToken(
        @FieldMap Map<String, String> params, 
        Callback<FacebookLoginUserResponse> callback
    );
    
    0 讨论(0)
提交回复
热议问题