Raw string in request body for request using modified
2 answers
Method # 1
Think of your "user: user" as JsonObject. So please post JsonObject instead of Raw String.
You can create a POJO class:
public class User{
public final String user;
User(String user) {
this.user = user;
}
}
Your method looks like this:
@POST(/login) void login(@BODY User user,Callback<LoginResponse>)
And call it like:
User user = new User("john");
login(user,Callback<LoginResponse>)
Since Retrofit uses Gson by default, User instances will be serialized as JSON as the only request body. Default content type: app / json
Method # 2
You can submit Raw String as form data with content type: application / x-www-form-urlencoded and just need the @FormUrlEncoded annotation .
Here's your method:
@FormUrlEncoded
@POST(/login)
void login(@Field("yourkey") String user,Callback<LoginResponse>)
you just need to replace "your key" with your api key - "user"
Call it like:
String user = "john";
login(user,Callback<LoginResponse>)
Ref :
How to clear all JSON in the body of the re-install
request
retrofit.http.Field retrofit.http.FieldMap
+1
source to share