Bhavesh Patel
- Forum posts: 2
Mar 2, 2017, 8:38:50 AM via Website
Mar 2, 2017 8:38:50 AM via Website
===>>>my interface
interface loginInterFace{
@POST("/Demo.php")
Call createUser(@Body User user);
=====>>>My Java Class
void submit() {
//The Retrofit builder will have the client attached, in order to get connection logs
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(URL)
.build();
loginInterFace api = retrofit.create(loginInterFace.class);
User user = new User(usernameInput.getText().toString().trim(),passwordInput.getText().toString().trim());
Call<User> apiCall = api.createUser(user);
apiCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.e("Call", "" + call);
Log.e("response", "" + response);
try {
User u1=response.body();
Log.e("response", "" + u1.getSuccess());
}catch (Exception e){
Log.e("Error=>",""+e.getMessage());
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.e("Onfailure call", "" + call);
Log.e("Onfailure Throwable", "" + t);
}
});
}
====>>My Model Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by Bhavesh Patel on 28-02-2017.
*/
public class User {
@SerializedName("username")
@Expose
String username;
@SerializedName("password")
@Expose
String password;
@SerializedName("success")
@Expose
String success;
@SerializedName("message")
@Expose
String message;
public User() {
}
public User(final String username, final String password) {
this.username = username;
this.password = password;
}
public User(String message, String success, String username, String password) {
this.message = message;
this.success = success;
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.