Retrofit 2.0 throwing "IllegalArgumentException: @Field parameters can only be used with form encoding". How to do right API query and fix it?
Your request is not encoded right, but are postman, so do change that :
@FormUrlEncoded@PUT("/api/register") Call<AuthRegisterUserModel> getStatus( @Field("username") String username, @Field("email") String email, @Field("password") String password, @Field("fbID") String fbID, @Field("gmailID") String gmailID, @Field("twitID") String twitID, @Field("gender") String gender, @Field("birthDate") String birthDate, @Field("location") String location, @Field("longitude") String longitude, @Field("latitude") String latitude, @Field("profileImage") String profileImage);
Tell me if it's ok.
The problem was because I try to PUT
e.g. longitude
\ latitude
\ location
with no value - empty String
.
I mean - there was a problem on API side. So to avoid that I changed method to this:
@FormUrlEncoded@PUT(ApiConstants.REGISTER_URL_PART)Call<RegisterModel> registerUser( @Field("username") String username, @Field("email") String email, @Field("password") String password, @Field("fbID") String fbID, @Field("gmailID") String gmailID, @Field("twitID") String twitID, @Field("gender") String gender, @Field("birthDate") String birthDate, @Nullable @Field("location") String location, @Nullable @Field("longitude") String longitude, @Nullable @Field("latitude") String latitude, @Field("profileImage") String profileImage);
Now, when I go no value for one of them, I simply don't enclose this field.