在android kitkat中,URLConnection的实现已被OkHttp取代,它如何调试呢?
OkHttp在这个目录中:external/okhttp/android/main/java/com/squareup/okhttp
当我打电话给UrlInstance.openConnection().getClass().getName()它时,它会出现com.android.okhttp.internal.http.HttpURLConnectionImpl
我该怎么调试呢?似乎我无法联想/android/main/java/com/squareup/okhttp/*到com.android.okhttp.*
当代码执行到 return streamHandler.openConnection(this);
/**
* Returns a new connection to the resource referred to by this URL.
*
* @throws IOException if an error occurs while opening the connection.
*/
public URLConnection openConnection() throws IOException {
return streamHandler.openConnection(this);
}
Run Code Online (Sandbox Code Playgroud)
向前走,但不能深入挖掘 com.squareup.okhttp.HttpHandler#openConnection
下图中调试器中突出显示的线程为灰色.
package com.squareup.okhttp;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
public class HttpHandler extends URLStreamHandler {
@Override protected URLConnection openConnection(URL url) throws IOException { …Run Code Online (Sandbox Code Playgroud) 根据一些参考资料,例如 Android 在内部使用 OkHttp 吗? Android 在 HttpUrlConnection 下内部正在使用(或至少正在使用)okHttp。仍然在最近的一些讨论中(例如,为什么 Android 的 HttpUrlConnection 不支持 HTTP/2?)建议使用来自 GitHub 的 okHttp 而不是 Android http API。所以我很困惑。有没有人有明确的答案?