无法将数据插入数据库
savePipelist();
private void savePipelist(final int pipesize, final int pipequantity) {
detail = "";
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<Pipelist> call = apiInterface.savePipelist(pipesize, pipequantity);
call.enqueue(new Callback<Pipelist>() {
@Override
public void onResponse(@NonNull Call<Pipelist> call, @NonNull Response<Pipelist> response) {
if (response.isSuccessful() && response.body() != null) {
Boolean success = response.body().getSuccess();
if (success) {
detail = response.body().getMessage().trim();
} else {
detail = response.body().getMessage().trim();
}
}else{
}
}
@Override
public void onFailure(@NonNull Call<Pipelist> call, @NonNull Throwable t) {
detail = t.getLocalizedMessage().trim();
}
});}`
ApiClient
public class ApiClient {
private static final String BASE_URL = "https://save.000webhostapp.com/";
private static Retrofit retrofit;
public static Retrofit getApiClient(){
if(retrofit==null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;}}
ApiInterface
public interface ApiInterface {
@FormUrlEncoded
@POST("save.php")
Call<Pipelist> savePipelist(
@Field("pipesize") int pipesize,
@Field("pipequantity") int pipequantity
);}
public class Pipelist {
@Expose
@SerializedName("id")private int id;
@Expose
@SerializedName("pipesize")private int pipesize;
@Expose
@SerializedName("pipequantity")private int pipequantity;
@Expose
@SerializedName("success")private Boolean success;
@Expose
@SerializedName("message")private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPipesize() {
return pipesize;
}
public void setPipesize(int pipesize) {
this.pipesize = pipesize;
}
public int getPipequantity() {
return pipequantity;
}
public void setPipequantity(int pipequantity) {
this.pipequantity = pipequantity;
}
每当我调用api statuscode is 200
时,响应正文始终为null。我收到的消息是这样的:
Response{protocol=h2, code=200, message=, url=https://save.000webhostapp.com/save.php}
任何帮助或建议都会受到赞赏。