I need make POST request with parameters "guid=1" in Body. i use Retrofit2
I try :
@POST("/api/1/model")
Call<ApiModelJson> getPostClub(@Body User body);
User Class:
public class User {
@SerializedName("guid")
String guid;
public User(String guid ) {
this.guid = guid;
}
MailActivity:
User user =new User ("1");
Call<ApiModelJson> call = service.getPostClub(user);
call.enqueue(new Callback<ApiModelJson>() {
@Override
public void onResponse(Response<ApiModelJson> response) {
}
@Override
public void onFailure(Throwable t) {
dialog.dismiss();
}
How make this request?
you have to call call.enqueue
, providing an instance of Callback< ApiModelJson>
, where you will get the response. enqueue
executes your backend call asynchronously. You can read more about call.enqueue
here
With code below, you can make the request synchronously:
ApiModelJson responseBody = call.execute();
If you want it to be asynchronous:
call.enqueue(new Callback<ApiModelJson>() {
@Override
public void onResponse(Response<ApiModelJson> response, Retrofit retrofit) {
}
@Override
public void onFailure(Throwable t) {
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.