Retrofit 2 disable encoding for post parameters

牧云@^-^@ 提交于 2021-01-27 04:09:22

问题


I am beginner in retrofit... I need send POST request with simple parameters

name : value

  • login[name] : some-name
  • login[pw] : some-pw
  • date : 2017-08-28T12:12:12+0200

so, I tried

@FormUrlEncoded
@POST(urlLogin)
Call<Login> signIn(@Field("login[name]") String name,
                    @Field("login[pw]") String pw,                          
                    @Field("date") String date);

that send to the server:

  • login%5Bname%5D : some-name
  • login%5Bpw%5D : some-pw
  • date : 2017-08-28T21%3A11%3A57%2B0200

next

@FormUrlEncoded
@POST(urlLogin)
Call<Login> signIn(@Field(value = "login[name]", encoded = true) String name,
                   @Field(value = "login[pw]", encoded = true) String pw,                          
                   @Field(value = "date", encoded = true) String date);

gives:

  • login%5Bname%5D : some-name
  • login%5Bpw%5D : some-pw
  • date : 2017-08-28T19%3A59%3A04+0200

next

@FormUrlEncoded
@POST(urlLogin)
Call<Login> signIn(@FieldMap Map<String, String> fieldsMap);

gives:

  • login%5Bname%5D : some-name
  • login%5Bpw%5D : some-pw
  • date : 2017-08-28T21%3A11%3A57%2B0200

next

@FormUrlEncoded
@POST(urlLogin)
Call<Login> signIn(@FieldMap(encoded = true) Map<String, String> fieldsMap);

gives:

  • login%5Bname%5D : some-name
  • login%5Bpw%5D : some-pw
  • date : 2017-08-28T19%3A59%3A04+0200

please, help me, what do i wrong? what wrong with date? why "+" are disabled for encoding and ":" are encoded? and why parameters name are encoded and how to disable this?

来源:https://stackoverflow.com/questions/45925251/retrofit-2-disable-encoding-for-post-parameters

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