Java 为什么我无法在android中使用改型从Api中获取body。而它';s返回代码500及其';s返回错误体中的所有数据

Java 为什么我无法在android中使用改型从Api中获取body。而它';s返回代码500及其';s返回错误体中的所有数据,java,php,android,android-studio,Java,Php,Android,Android Studio,我不知道为什么我在errorBody内收到了所有数据,但我想在body内收到数据。我是php新手,请帮助我,这对我来说非常重要。它的返回代码500从后端你可以检查我的日志我添加所有的细节在这里 邮递员 Php脚本 Api接口 每当您收到500个代码时,这意味着错误来自您的后端服务器,因此需要检查android后端之间的API内容。您的API返回错误响应代码检查为什么会发生这种情况。这个问题肯定只存在于php方面。 [ { "id": "15", "path

我不知道为什么我在errorBody内收到了所有数据,但我想在body内收到数据。我是php新手,请帮助我,这对我来说非常重要。它的返回代码500从后端你可以检查我的日志我添加所有的细节在这里

邮递员

Php脚本

Api接口


每当您收到500个代码时,这意味着错误来自您的后端服务器,因此需要检查android后端之间的API内容。

您的API返回错误响应代码检查为什么会发生这种情况。这个问题肯定只存在于php方面。
[
    {
        "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
$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);

?>
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;
    }
}
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();
}
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