POST data to the server require backhend program which is post your data to the database in the server.....
Retrofit Post require RESTAPI and POJO Class ....
API Interface
public interface Api {
@POST("/upload/{new}.json")
Call<User> setData(@Path("new") String s1, @Body User user);
}
Retrofit Object
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("here-your-url")
.addConverterFactory(GsonConverterFactory.create())
.build();
APi object
Api api = retrofit.create(Api.class);
Retrofit Call
Call<User> call = api.setData("mahesh", new User("mahesh", "delhi"));
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
t1.setText("Success");
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.d("sam", "fail");
t1.setText("fail");
}
});
POJO class //this class you create just put your json data into this POJOConvertion
public class User {
String name;
String address;
public User(String name, String address) {
this.address = address;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
enjoy coding.
If you want any practice for the Retrofit than please use this Retrofit + Firebase