Как установить параметры запроса для параметров типа json при вызове из MainActivity?
Это мой интерфейсный класс, в котором есть аннотация заголовков типа application / json и использующий метод post и вызов вызова, в котором используется аннотация тела, имеющая модель для запроса параметров
public interface ApiStorePhotoInterface {
@Headers("Content-Type: application/json")
@POST("photo/st/v7")
Call<PhotoStoreMainModel> getResponse(@Body ParamModel paramModel);
}
Здесь ParamModel - модель json и используется для вызова.
2 модели параметров для @Body в интерфейсе
Эта Модель содержит значения со списком, в котором ParamProductDetailModel является второй моделью в нем.
1-я модель Param -
public class ParamModel {
@SerializedName("apiKey")
@Expose
private String apiKey;
@SerializedName("affId")
@Expose
private String affId;
@SerializedName("act")
@Expose
private String act;
@SerializedName("latitude")
@Expose
private String latitude;
@SerializedName("longitude")
@Expose
private String longitude;
@SerializedName("devinf")
@Expose
private String devinf;
@SerializedName("appver")
@Expose
private String appver;
@SerializedName("productDetails")
@Expose
private List<ParamProductDetailModel> productDetails = null;
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getAffId() {
return affId;
}
public void setAffId(String affId) {
this.affId = affId;
}
public String getAct() {
return act;
}
public void setAct(String act) {
this.act = act;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getDevinf() {
return devinf;
}
public void setDevinf(String devinf) {
this.devinf = devinf;
}
public String getAppver() {
return appver;
}
public void setAppver(String appver) {
this.appver = appver;
}
public List<ParamProductDetailModel> getProductDetails() {
return productDetails;
}
public void setProductDetails(List<ParamProductDetailModel> productDetails) {
this.productDetails = productDetails;
}
}
2-я модель Param -
public class ParamProductDetailModel {
@SerializedName("productId")
@Expose
private String productId;
@SerializedName("qty")
@Expose
private String qty;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getQty() {
return qty;
}
public void setQty(String qty) {
this.qty = qty;
}
}
Это клиентский класс
Клиентский класс-
Это класс модифицированных строителей
public class ApiStorePhotoClient {
private static final String BASE_URL = " https://services.something.com/api/";
private static ApiStorePhotoInterface apiInterface;
public static ApiStorePhotoInterface getApi() {
if (apiInterface == null) {
apiInterface = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiStorePhotoInterface.class);
}
return apiInterface;
}
}
Теперь в моем основном классе -
ApiStorePhotoInterface apiInterface = ApiStorePhotoClient.getApi();
Call<PhotoStoreMainModel> call = apiInterface.getResponse("What to write here??");
Как отправить запрос внутри модели в getResponse ()?
PhotoStoreMainModel - модель ответа. Код имеет модель с 3 ответами, в которой PhotoStoreMainModel является одной из них, и модель с 2 параметрами запроса, которая размещена выше.
Как отправить параметры запроса в @body ParamModel внутри Mainclass в getResponse ()?
Как установить линии для звонка в моем классе MainActivity?
Ожидаю результата, но не могу попасть в API из-за параметров запроса