MinSdkVersion
为17
,targetSdkVersion
为25
。在此应用程序中,我使用Rx连接服务并进行改造,此代码无效api 17
我无法连接到webService
,下面是我的代码:
我的RetrofitApi.java
:
public class RetrofitApi {
private static PublicApi retrofit = null;
public static PublicApi getClient(String url) {
retrofit = new Retrofit.Builder()
.baseUrl(url)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build().create(PublicApi.class);
return retrofit;
}
}
我的PublicApi.java
:
public interface PublicApi {
@GET("/web_service/mobile/rest")
Observable<LastNews> lastNews(@Query("function") String function);
}
并且:
PublicApi publicApi = RetrofitApi.getClient("https://xxx.xxx.xxx/");
CompositeDisposable mCompositeDisposable = new CompositeDisposable();
mCompositeDisposable.add(publicApi.lastNews("getLastNews")
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(this::responseLastNews, this::errorLastNews));
private void responseLastNews(LastNews lastNewses){
}
private void errorLastNews(Throwable error) {
Log.i("LOG", error.getMessage());
}
当我在API 17
上测试时遇到错误并且没有连接到服务器。告诉我:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.