4

所以我最近了解了 Stetho,并想实现它来拦截网络请求。但是,我找不到有关如何为 URLConnection 执行此操作的示例:

这是我的 VolleySingleton 课程的片段。

private RequestQueue getRequestQueue() {
    HurlStack hurlStack = new HurlStack() {
        @Override
        protected HttpURLConnection createConnection(URL url) throws IOException {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url);
            try {
                httpsURLConnection.setSSLSocketFactory(getSSLSocketFactory());
                httpsURLConnection.setHostnameVerifier(getHostnameVerifier());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return httpsURLConnection;
        }
    };

    if(mRequestQueue == null) {
        // this will make sure that this particular instance will last the lifetime of the app
        // getApplicationContext() is key, it keeps you from leaking the Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext(), hurlStack);
    }
    return mRequestQueue;
}

根据文档: 如果您使用的是 HttpURLConnection,则可以使用 StethoURLConnectionManager

但是在检查课程后我不知道该怎么做。也许有人在这个问题上有经验?非常感谢。

来源:https ://github.com/facebook/stetho/blob/master/stetho-urlconnection/src/main/java/com/facebook/stetho/urlconnection/StethoURLConnectionManager.java

来源: http: //facebook.github.io/stetho/#integrations

4

0 回答 0