Stetho和chrome:检查待处理的REST请求

时间:2018-02-12 16:35:53

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

我使用Stetho,Retrofit和OkHttp与Chrome开发者工具进行调试,一切似乎都运行正常,我看到我的本地数据库内容,我可以检查我的用户界面,但是如果我对我做一些REST请愿在启用了网络检查的服务器上,请愿仍然是"待定",但如果我复制网址并粘贴到Chrome标签页上,请愿书就会正确执行,我也不知道发生了什么。

enter image description here

这些是我的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'

1 个答案:

答案 0 :(得分:3)

我在这里找到了答案 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());

这是 CORRECT 版本:

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