在我的项目中,我有两个模型,我想将客户的信息发送到服务器并从服务器获得响应。
在Android Studio中,我想通过retrofit将模型发送到服务器。当我发送请求时,retrofit向我返回一个空响应。有人可以帮我吗?
这是我的customer_role模型:
public class customers_role {
@SerializedName("customers_models")
private customers_model customers_models;
@SerializedName("mobile")
private String mobile;
@SerializedName("phone")
private String phone;
@SerializedName("first_job")
private String first_job;
@SerializedName("second_job")
private String second_job;
@SerializedName("first_address")
private String first_address;
@SerializedName("second_address")
private String second_address;
@SerializedName("postal_code")
private String postal_code;
@SerializedName("nik_name")
private String nik_name;
@SerializedName("description")
private String description;
@SerializedName("created_at")
private String created_at;
@SerializedName("updated_at")
private String updated_at;
@SerializedName("status")
private boolean status;
public customers_role() {
}
}
这是customer_model:
public class customers_model {
@SerializedName("id")
private Integer id;
@SerializedName("name")
private String name;
@SerializedName("family")
private String family;
@SerializedName("code")
private String code;
@SerializedName("father")
private String father;
@SerializedName("birthday")
private String birthday;
@SerializedName("created_at")
private String created_at;
@SerializedName("updated_at")
private String updated_at;
@SerializedName("status")
private boolean status;
public customers_model() {
}
public customers_model(String name, String family, String code, String father, String birthday) {
this.name = name;
this.family = family;
this.code = code;
this.father = father;
this.birthday = birthday;
}
}
我的界面是:
@Headers("Accept: application/json")
@POST("customers")
Call<customers_role> send_info(@Header("Authorization") String token, @Body customers_role info);
谢谢
`
答案 0 :(得分:0)
得到按摩فیلد فلان اجرابیه
我认为您需要填写项目:
name
family
code
father
birthday
然后像使用customers_role
也许应该是这样的:
@Headers("Accept: application/json")
@POST("customers")
Call<customers_role> send_info(@Header("Authorization") String token, @Body customers_model model);
希望它会为您提供帮助
答案 1 :(得分:0)
当我对@Post注释有疑问时,请执行以下操作:
@Headers("Accept: application/json")
@POST
Call<customers_role> send_info(@Url String url, @Body customers_role customersRole);