简体   繁体   English

如何通过rx改装获得请求url? -安卓

[英]How can I get request url from retrofit with rx ? - Android

MinSdkVersion of my application is 17 and targetSdkVersion is 25 .In this application I am connecting to service with Rx and retrofit, this code don't work on api 17 I can't connect to webService , bellow is my code : MinSdkVersion我申请的是17targetSdkVersion25 。在这个应用我连接,其中Rx和改造维修,这段代码不上工作api 17我无法连接到webService ,波纹管是我的代码:

My RetrofitApi.java : 我的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;
    }
}

My PublicApi.java : 我的PublicApi.java

public interface PublicApi {

    @GET("/web_service/mobile/rest")
    Observable<LastNews> lastNews(@Query("function") String function);
}

And : 和:

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

When I tested on API 17 get me error and don't connect to server.Told me : 当我在API 17上进行测试时,收到错误消息并无法连接到服务器。告诉我:

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

Your base URL (**https**://xxx.xxx.xxx/) is secured with SSL , you need to implement SSL connection to get it working. 您的基本URL (**https**://xxx.xxx.xxx/)已通过SSL ,您需要实现SSL连接才能使其正常工作。

Please refer this link 请参考此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM