gpt4 book ai didi

android - 在 WebViewClient 中覆盖 shouldInterceptRequest 时系统崩溃

转载 作者:IT王子 更新时间:2023-10-28 23:33:07 28 4
gpt4 key购买 nike

目标:

覆盖 WebView 发出的所有请求并自己发出请求(最终设置代理)。

代码:

@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url == null || url.trim().equals(""))
return null;

final DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getConnectionManager().closeExpiredConnections();
final HttpUriRequest httpRequest = new HttpGet(url);

try {
final HttpResponse response = httpClient.execute(httpRequest);
final Header[] headers = response.getHeaders(CONTENT_TYPE);
String mimeType = "";
String encoding = "";
if (headers != null && headers.length > 0) {
final String type = headers[0].getValue();
final int semicolonIndex = type.indexOf(';');
if (semicolonIndex != -1) {
mimeType = type.substring(0, semicolonIndex).trim();
encoding = type.substring(semicolonIndex + 1).trim();
final int equalsIndex = encoding.indexOf('=');
if (equalsIndex != -1)
encoding = encoding.substring(equalsIndex + 1).trim();
} else
mimeType = type;
}

return new WebResourceResponse(mimeType, encoding, response.getEntity().getContent());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().closeExpiredConnections();
}
return null;
}

所有请求似乎都顺利通过,但最终我得到了一个堆栈跟踪,其中包含以下两个问题之一:

3 15:07:28.650 E/InputDispatcher( 3981): channel '40d76268 com.secure.browser/com.secure.browser.SecureBrowserActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
01-03 15:07:28.650 E/InputDispatcher( 3981): channel '40d76268 com.secure.browser/com.secure.browser.SecureBrowserActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

这显然表明操作系统耗尽了文件描述符 (fid)

01-03 15:29:36.810 I/DEBUG   ( 5798):     5903cd34  ac81c0b7  /system/lib/libdvm.so
01-03 15:29:38.380 I/DEBUG ( 5798): debuggerd committing suicide to free the zombie!
01-03 15:29:38.380 I/BootReceiver( 3981): Copying /data/tombstones/tombstone_07 to DropBox

(SYSTEM_TOMBSTONE)

这意味着我认为操作系统遇到了低级问题。

我用的是3.0+,所以应该支持该功能。

当我打开 javascript 时,或者在没有 javascript 的情况下浏览了一段时间后,这通常会失败。

最佳答案

该方法已弃用。尝试相同方法的其他签名。

关于android - 在 WebViewClient 中覆盖 shouldInterceptRequest 时系统崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806562/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com