Android Emulator中的HTTP代理适用于浏览器,而不适用于WebView
我的开发环境落后于HTTP代理。在Android emulator中,我可以在wifi首选项中设置我的代理地址和凭据。然后,当我在浏览器中查看页面时,系统会提示我重新输入指定主机的凭据。不知道为什么我必须再次输入它们,但它可以工作,我可以查看页面 然后,我有一个应用程序,它带有一个Web视图,可以加载相同的页面。该应用程序具有internet权限:Android Emulator中的HTTP代理适用于浏览器,而不适用于WebView,android,Android,我的开发环境落后于HTTP代理。在Android emulator中,我可以在wifi首选项中设置我的代理地址和凭据。然后,当我在浏览器中查看页面时,系统会提示我重新输入指定主机的凭据。不知道为什么我必须再次输入它们,但它可以工作,我可以查看页面 然后,我有一个应用程序,它带有一个Web视图,可以加载相同的页面。该应用程序具有internet权限: <uses-permission android:name="android.permission.INTERNET"/> <us
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
但是。。。当我尝试查看页面时,我得到代理的错误页面,说用户名和密码输入不正确。这对我来说意味着应用程序正在成功读取代理地址,但就像浏览器没有读取凭据一样。然后,它就无法在完成请求之前显示与浏览器请求凭据相同的对话框
是否有办法启用此对话框(是否内置?)或手动指定代理详细信息?查看android浏览器源代码,以下内容很清楚:
主机设置为“{proxy}:{port}”
和域设置为空字符串,触发附加的WebViewClient
的onReceivedHttpAuthRequest
WebViewClient
的新类,并从中复制OnReceiveDhtPauthRequest
方法mPagesDialogHandler
<代码>上下文是您的活动
HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(context, host, realm);
dialog.setOkListener(new HttpAuthenticationDialog.OkListener() {
public void onOk(String host, String realm, String username, String password) {
handler.proceed(username, password);
}
});
dialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() {
public void onCancel() {
handler.cancel();
}
});
dialog.show();
WebViewClient
用于web视图根据您的回答,我得到的对话框,输入用户名和密码后,我无法登录。我需要再次加载webview url吗?
HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(context, host, realm);
dialog.setOkListener(new HttpAuthenticationDialog.OkListener() {
public void onOk(String host, String realm, String username, String password) {
handler.proceed(username, password);
}
});
dialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() {
public void onCancel() {
handler.cancel();
}
});
dialog.show();