gpt4 book ai didi

java - Android - Retrofit2 - java.security.cert.CertPathValidatorException : Trust anchor for certification path not found

转载 作者:行者123 更新时间:2023-11-29 19:10:50 26 4
gpt4 key购买 nike

我想从服务器 ( https://data.egov.kz/api/v2/zheke_zhane_zandy_tulgalardy_k1/v6?pretty ) 获取数据作为 json 对象数组。但我得到这个日志: java.security.cert.CertPathValidatorException:找不到证书路径的信任 anchor 。 我正在使用 Retrofit2,这里是我的代码:

主 Activity .java

public class MainActivity extends AppCompatActivity
implements GetAdmissionSchedule.GetAdmissionScheduleInterface {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GetAdmissionSchedule getAdmissionSchedule = new GetAdmissionSchedule(this);
getAdmissionSchedule.getAdmissionScheduleList();
}

@Override
public void getAdmissionSchedule(List<AdmissionSchedule> admissionScheduleList) {
// here i get my data
}

}

GetAdmissionSchedule.java

public class GetAdmissionSchedule {

private GetAdmissionScheduleInterface getAdmissionScheduleInterface;

public GetAdmissionSchedule(GetAdmissionScheduleInterface getAdmissionScheduleInterface) {
this.getAdmissionScheduleInterface = getAdmissionScheduleInterface;
}

public interface GetAdmissionScheduleInterface {
void getAdmissionSchedule(List<AdmissionSchedule> admissionScheduleList);
}

public void getAdmissionScheduleList() {
DataEgovApi service = DataEgovBaseURL.getRetrofit();
Call<List<AdmissionSchedule>> call = service.getAdmissionScheduleList();
call.enqueue(new Callback<List<AdmissionSchedule>>() {
@Override
public void onResponse(Call<List<AdmissionSchedule>> call, Response<List<AdmissionSchedule>> response) {
Log.d("MyLogs", "MVD: getAdmissionScheduleList " + response.code());
getAdmissionScheduleInterface.getAdmissionSchedule(response.body());
}

@Override
public void onFailure(Call<List<AdmissionSchedule>> call, Throwable t) {
Log.d("MyLogs", "MVD: getAdmissionScheduleList " + t.getLocalizedMessage());
getAdmissionScheduleInterface.getAdmissionSchedule(null);
}
});
}

}

DataEgovBaseURL.java

public class DataEgovBaseURL {

private static final String BASE_URL = "https://data.egov.kz/";
private static Retrofit retrofit = null;

public static DataEgovApi getRetrofit() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();

}
return retrofit.create(DataEgovApi.class);
}

}

DataEgovApi.java

public interface DataEgovApi {

@GET("api/v2/zheke_zhane_zandy_tulgalardy_k1/v6?pretty")
Call<List<AdmissionSchedule>> getAdmissionScheduleList();

}

AdmissionSchedule.java(我的 POJO 类)

public class AdmissionSchedule {

@SerializedName("id")
@Expose
private String id;
@SerializedName("vremia")
@Expose
private String vremia;
@SerializedName("adres_ru")
@Expose
private String adresRu;
@SerializedName("doljnost_ru")
@Expose
private String doljnostRu;
@SerializedName("name_ru")
@Expose
private String nameRu;
@SerializedName("data")
@Expose
private String data;
@SerializedName("adres_kz")
@Expose
private String adresKz;
@SerializedName("doljnost_kz")
@Expose
private String doljnostKz;
@SerializedName("name_kz")
@Expose
private String nameKz;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getVremia() {
return vremia;
}

public void setVremia(String vremia) {
this.vremia = vremia;
}

public String getAdresRu() {
return adresRu;
}

public void setAdresRu(String adresRu) {
this.adresRu = adresRu;
}

public String getDoljnostRu() {
return doljnostRu;
}

public void setDoljnostRu(String doljnostRu) {
this.doljnostRu = doljnostRu;
}

public String getNameRu() {
return nameRu;
}

public void setNameRu(String nameRu) {
this.nameRu = nameRu;
}

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

public String getAdresKz() {
return adresKz;
}

public void setAdresKz(String adresKz) {
this.adresKz = adresKz;
}

public String getDoljnostKz() {
return doljnostKz;
}

public void setDoljnostKz(String doljnostKz) {
this.doljnostKz = doljnostKz;
}

public String getNameKz() {
return nameKz;
}

public void setNameKz(String nameKz) {
this.nameKz = nameKz;
}

}

最佳答案

您的服务器 url 是 https 并且证书已经无效。

enter image description here

https 更改为 http 即可。

否则您可以在服务器上安装有效的 SSL 证书。

enter image description here

关于java - Android - Retrofit2 - java.security.cert.CertPathValidatorException : Trust anchor for certification path not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45411927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com