Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在截击中使用听诊器?_Android_Facebook_Okhttp_Stetho - Fatal编程技术网

Android 如何在截击中使用听诊器?

Android 如何在截击中使用听诊器?,android,facebook,okhttp,stetho,Android,Facebook,Okhttp,Stetho,为我的请求创建了一个截击单例类。这是我的单例类 public class VolleySingleton { private static VolleySingleton instance; private RequestQueue reQueue; private VolleySingleton(Context context) { reQueue = Volley.newRequestQueue(context,new OkHttpStack(ne

为我的请求创建了一个截击单例类。这是我的单例类

public class VolleySingleton {

    private static VolleySingleton instance;
    private RequestQueue reQueue;

    private VolleySingleton(Context context) {
        reQueue = Volley.newRequestQueue(context,new OkHttpStack(new OkHttpClient()));
    }

    public static VolleySingleton getInstance(Context context) {
        if(instance == null)
            instance = new VolleySingleton(context);
        return instance;
    }

    public RequestQueue getRequestQueue() {
        return reQueue;
    }

    public <T> void addToRequestQueue(Request<T> request) {
        request.setTag("app");
        request.setShouldCache(false);
        request.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        getRequestQueue().add(request);
    }
}
我还在我的应用程序中初始化了听诊器

Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(
                                Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(
                                Stetho.defaultInspectorModulesProvider(this))
                        .build());
问题是,当我调试时,我无法在浏览器中获取应用程序发出的网络调用。我不确定哪里出错了!救命啊

在项目中添加此文件

试试这个:

Stetho.initializeWithDefaults(this);
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
mRequestQueue = Volley.newRequestQueue(getApplicationContext(), new OkHttpStack(client));
具有以下依赖项:

implementation 'com.facebook.stetho:stetho-okhttp:(insert latest version)'
implementation 'com.squareup.okhttp3:okhttp:(insert latest version)'

@Sabeeh的答案是正确的,只更新你的gradle中的库

compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp:1.3.1'
compile 'com.facebook.stetho:stetho-urlconnection:1.3.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
现在在项目的应用程序类中添加以下内容

    Stetho.initializeWithDefaults(this);

    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.networkInterceptors().add(new StethoInterceptor());
    mRequestQueue = Volley.newRequestQueue(this, new OkHttpStack(okHttpClient));

导入您的库,但我们会看到OkHttpStack(okHttpClient)出现错误,因此您只需要复制@bryanstern提供的代码,因此,如果您想在不使用OkHttp堆栈的情况下使用Stetho进行截击,请创建文件导入并享受它


请参考此链接

您好,我很好奇您如何使用OkHTTPStack处理SSL?我目前正在Volley中使用带有SSL的HurlStack,希望切换到OkHTTP,以便使用Stetho进行网络跟踪。您好,我很好奇您如何使用OkHTTPStack处理SSL?我目前正在Volley中使用带有SSL的HurlStack,并希望切换到OkHTTP,以便使用Stetho进行网络跟踪。
    Stetho.initializeWithDefaults(this);

    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.networkInterceptors().add(new StethoInterceptor());
    mRequestQueue = Volley.newRequestQueue(this, new OkHttpStack(okHttpClient));