大家 最近,当我找到
时,我用HttpUrlConnection模块进行代码研究 ... ...
// Fall back to a built-in stream handler if the user didn't supply one
if (protocol.equals("file")) {
streamHandler = new FileHandler();
} else if (protocol.equals("ftp")) {
streamHandler = new FtpHandler();
} else if (protocol.equals("http")) {
try {
String name = "com.android.okhttp.HttpHandler";
streamHandler = (URLStreamHandler) Class.forName(name).newInstance();
} catch (Exception e) {
throw new AssertionError(e);
}
} else if (protocol.equals("https")) {
try {
String name = "com.android.okhttp.HttpsHandler";
streamHandler = (URLStreamHandler) Class.forName(name).newInstance();
} catch (Exception e) {
throw new AssertionError(e);
}
} else if (protocol.equals("jar")) {
... ...
没有Java的名称是“com.android.okhttp.HttpHandler”或“com.android.okhttp.HttpsHandler”,
那么& Android加载这个类的地方?
答案 0 :(得分:1)
Question: Why PackageName is "com.android.okhttp" not "com.squareup.okhttp"? #2201
包名称为 com.android.okhttp 的原因是因为有jarjar rules以该名称重新包装它。
答案 1 :(得分:0)
你可以在android googlesource找到HttpHandler。
基本上,com.android.okhttp.HttpHandler没有意义,它应该是squareup.okhttp.HttpHandler,它扩展了URLStreamHandler并包含一些方法openConnection()和getDefaultPort()