Trong bộ công cụ android, triển khai URLConnection đã được thay thế bằng OkHttp, Làm cách nào để gỡ lỗi?Cách gỡ lỗi "com.android.okhttp"
Các OkHttp là trong thư mục này: external/okhttp/android/main/java/com/squareup/okhttp
Khi tôi gọi UrlInstance.openConnection().getClass().getName()
, nó hiện com.android.okhttp.internal.http.HttpURLConnectionImpl
Làm thế nào tôi có thể gỡ lỗi nó? Dường như tôi không thể kết hợp /android/main/java/com/squareup/okhttp/*
đến com.android.okhttp.*
Khi mã thực thi vào 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);
}
Go tiến xa hơn, nhưng không thể thâm nhập vào các com.squareup.okhttp.HttpHandler#openConnection
The nhấn mạnh thread trong trình gỡ rối trong hình bên dưới có màu xám.
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 {
return newOkHttpClient(null /* proxy */).open(url);
}
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
if (url == null || proxy == null) {
throw new IllegalArgumentException("url == null || proxy == null");
}
return newOkHttpClient(proxy).open(url);
}
@Override protected int getDefaultPort() {
return 80;
}
protected OkHttpClient newOkHttpClient(Proxy proxy) {
OkHttpClient client = new OkHttpClient();
client.setFollowProtocolRedirects(false);
if (proxy != null) {
client.setProxy(proxy);
}
return client;
}
}
Bạn muốn làm gì chính xác? – eleven
@Foxinsocks OkHttp nằm trong các nguồn của AOSP bên ngoài/okhttp/android/main/java/com/squareup/okhttp', nhưng, lớp thời gian chạy là 'com.android.okhttp.internal.http.HttpURLConnectionImpl'. Tôi muốn làm theo các bước mã từng bước, nhưng bây giờ, tôi không thể – log1000
@ Foxinsocks tôi muốn thực hiện theo việc thực thi mã. Nhưng, tôi không biết làm thế nào để assoiate các nguồn OkHttp để 'com.android.okhttp' – log1000