Я не знаю, почему я получил все свои данные внутри errorBody, но я хочу получать данные внутри тела. Я новичок в случае php, пожалуйста, помогите мне, это очень важно для меня. это код возврата 500 из бэкэнда, вы можете проверить мой журнал, я добавляю все подробности здесь.
Почтальон
[
{
"id": "15",
"pathToFile": "1642584690_1590649486.mp4",
"categoryId": "9"
},
{
"id": "16",
"pathToFile": "1546153059_1590651415.mp4",
"categoryId": "9"
},
{
"id": "17",
"pathToFile": "https:/mozeloapp.in/viddo/UploadVideo/1590662957575.mp4",
"categoryId": "9"
}
]
Php скрипт
<?php
$getCategoryId=$_GET['categoryId'];
$connection = mysqli_connect("localhost","u781384687_sudhakarsinu","Prabhat@01","u781384687_vdimazaapp");
if($getCategoryId){
$sql = "SELECT *from all_video where categoryId='$getCategoryId'";
}else{
$sql = "SELECT *from all_video";
}
$result = mysqli_query($connection,$sql);
$json_array = array();
while ($row = mysqli_fetch_assoc($result)) {
// $json_array[] = $row;
array_push($json_array,
array(
"id"=> $row['id'],
"pathToFile"=> $row['pathToFile'],
"categoryId" => $row['categoryId']));
}
echo json_encode($json_array);
mysqli.close($connection);
?>
Класс Pojo
package com.example.retrofitapi;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class VideoModel {
@SerializedName("id")
@Expose
private String id;
@SerializedName("pathToFile")
@Expose
private String pathToFile;
@SerializedName("categoryId")
@Expose
private String categoryId;
public VideoModel() {
}
public VideoModel(String id, String pathToFile, String categoryId) {
this.id = id;
this.pathToFile = pathToFile;
this.categoryId = categoryId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPathToFile() {
return pathToFile;
}
public void setPathToFile(String pathToFile) {
this.pathToFile = pathToFile;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
}
Интерфейс API
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
public interface VideoApi {
String BASE_URL = "https://mozeloapp.in/";
String FEED_URL = "viddo/retrivevideo.php";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
@GET(FEED_URL)
Call<List<VideoModel>>getVideo();
}
ManiActivity
package com.example.retrofitapi;
import androidx.annotation.LongDef;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.io.IOException;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
VideoApi videoApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoApi = VideoApi.retrofit.create(VideoApi.class);
Call<List<VideoModel>> call = videoApi.getVideo();
call.enqueue(new Callback<List<VideoModel>>() {
@Override
public void onResponse(Call<List<VideoModel>> call, Response<List<VideoModel>> response) {
try {
Log.d("VIDEOLINK", "onResponse: error code"+response.errorBody().string());
Log.d("VIDEOLINK", "onResponse: code "+response.code());
Log.d("VIDEOLINK", "onResponse: body "+response.body());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<List<VideoModel>> call, Throwable t) {
}
});
}
}
Кот журнала
2020-05-28 17:24:07.772 12869-12869/com.example.retrofitapi D/VIDEOLINK: onResponse: error code[{"id":"15","pathToFile":"1642584690_1590649486.mp4","categoryId":"9"},{"id":"16","pathToFile":"1546153059_1590651415.mp4","categoryId":"9"},{"id":"17","pathToFile":"https:\/mozeloapp.in\/viddo\/UploadVideo\/1590662957575.mp4","categoryId":"9"}]
2020-05-28 17:24:07.772 12869-12869/com.example.retrofitapi D/VIDEOLINK: onResponse: code 500
2020-05-28 17:24:07.772 12869-12869/com.example.retrofitapi D/VIDEOLINK: onResponse: body null