如何从rx改造中获取请求URL? - Android

时间:2017-07-13 05:55:58

标签: android retrofit rx-java rx-android okhttp3

我的应用程序的{p> MinSdkVersion17targetSdkVersion25。在此应用程序中,我使用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.

1 个答案:

答案 0 :(得分:0)

您的基本网址(**https**://xxx.xxx.xxx/)SSL保护,您需要实施SSL连接才能使其正常运行。

请参阅this link