2

When I used to click on submit button by filing all the details I am getting response 400. So can you Please help me to get out of it. Below There is my Postman. I'm using the library retrofit 2.5.0

My POJO Class

public class Signup {

@SerializedName("email")
@Expose
private String email;

@SerializedName("password")
@Expose
private String password;

@SerializedName("role")
@Expose
private String role;

public Signup(String email, String password, String role) {
    this.email = email;
    this.password = password;
    this.role = role;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getRole() {
    return role;
}

public void setRole(String role) {
    this.role = role;
}
}

Here is my Interface in which i send only email, role and password

My Interface

public interface SignupApiService {

@POST("users")
@FormUrlEncoded
Call<Signup> savePost(@Field("email") String email,
                      @Field("password") String password,
                      @Field("role") String role);
}

This is My Java Class

public class SignupClient {

private static SignupClient mInstance;
private static Retrofit retrofit;
private static final String BASE_URL = "http://74.207.233.160/api/v1/";

private SignupClient(){
    retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

public static synchronized SignupClient getInstance() {
    if (mInstance == null){
        mInstance = new SignupClient();
    }
    return mInstance;
}

public SignupApiService getApi() {
    return retrofit.create(SignupApiService.class);
}
}

And This My Main Activity

progressBar.setVisibility(View.VISIBLE);
                Call<Signup> call = SignupClient
                        .getInstance().getApi()
                        .savePost(email, password, role);

                call.enqueue(new Callback<Signup>() {
                    @Override
                    public void onResponse(Call<Signup> call, Response<Signup> response) {
                        int statusCode = response.code();
                        progressBar.setVisibility(View.GONE);
                        Log.d("SignupActivity", "onResponse" +statusCode);

                    }

                    @Override
                    public void onFailure(Call<Signup> call, Throwable t) {
                        Toast.makeText(SignupActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

PostMan My Postam

Rutvik Bhatt
  • 3,185
  • 1
  • 16
  • 28

1 Answers1

1

try this way

public interface SignupApiService {

@POST("users")
@FormUrlEncoded
Call<Signup> savePost(@Field("user[email]") String email,
                      @Field("user[password]") String password,
                      @Field("user[role]") String role);
}
Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33