【问题标题】:How can I get request url from retrofit with rx ? - Android如何使用 rx 从改造中获取请求 url? - 安卓
【发布时间】:2017-12-17 18:04:07
【问题描述】:

我的应用程序的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.

【问题讨论】:

  • 尝试从 baseUrl 或 @GET 参数中删除“/web_service”,因为它被占用了两次。但我不确定这是错误的原因。
  • @Dmitry Gorkovets.Not 工作。
  • 可能与 Rx 无关。检查this post
  • 如何使用rxjava在retrofit 2.0中获取请求url?
  • @Jo Jo Roid 您可以使用Stetho 来查看您的网络请求

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


【解决方案1】:

您的基本 URL (**https**://xxx.xxx.xxx/)SSL 保护,您需要实现 SSL 连接才能使其正常工作。

请参考this link

【讨论】:

    猜你喜欢
    • 2016-12-25
    • 2020-06-20
    • 2018-12-09
    • 1970-01-01
    • 2015-10-02
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多