【问题标题】:Stetho and chrome:inspect pending REST petitionsStetho 和 chrome:检查未决的 REST 请愿书
【发布时间】:2018-07-22 21:43:13
【问题描述】:

我将 Stetho、Retrofit 和 OkHttp 与 Chrome 开发人员工具一起用于调试目的,似乎一切正常,我看到了我的本地数据库内容,我可以检查我的 UI,但如果我对我的服务器进行一些 REST 请愿启用网络检查后,请愿书仍处于“待处理”状态,但如果我复制 URL 并粘贴到 Chrome 选项卡上,请愿书会正确执行,但我不知道发生了什么。

这些是我的 gradle 导入:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'

【问题讨论】:

    标签: android google-chrome google-chrome-devtools android-debug stetho


    【解决方案1】:

    我在这里找到了答案 https://github.com/facebook/stetho/issues/346

    我不小心使用了常规拦截器而不是网络拦截器。

    所以这是我的错误版本

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.addInterceptor(new StethoInterceptor());
    

    这是正确的版本:

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.addNetworkInterceptor(new StethoInterceptor());
    

    【讨论】:

    • 既然你已经在使用stetho,你可以去掉okhttp拦截器——httpClient.addInterceptor(logging);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多