我正在尝试在我的应用程序中运行基本身份验证,但是我收到此错误会关闭活动,因此我无法通过。不确定我做错了什么?也许过早地打电话给handler.proceed
?
错误:
08-20 09:52:13.793 8627-8836/com.example.app E/external/webkit/Source/WebKit/android/WebCoreSupport/WebRequest.cpp﹕ setAuth called on a WebRequest not in STARTED state (state=5)
代码:
@Override
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler,
String host, String realm) {
super.onReceivedHttpAuthRequest(view, handler, host, realm);
if (username == null) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Please Log In");
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.VERTICAL);
// Set an EditText view to get user input
final EditText usernameInput = new EditText(getActivity());
usernameInput.setHint("Username");
usernameInput.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
layout.addView(usernameInput);
final EditText passwordInput = new EditText(getActivity());
passwordInput.setHint("Password");
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
layout.addView(passwordInput);
alert.setView(layout);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
username = usernameInput.getText().toString();
password = passwordInput.getText().toString();
reloadWebView();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
} else {
handler.proceed(username, password);
}
//编辑:
我现在修改了我的代码,以便用户名和密码只是硬编码:
@Override
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler,
String host, String realm) {
super.onReceivedHttpAuthRequest(view, handler, host, realm);
handler.proceed("username", "password");
}
但同样的错误......不知道这里的问题是什么..
答案 0 :(得分:1)
通过摆脱:
解决了这个问题super.onReceivedHttpAuthRequest(view, handler, host, realm);
答案 1 :(得分:0)
我刚刚阅读了the WebRequest.cpp file,看起来你在第463行的setAuth中创建了错误消息,因为你的WebRequest无法在第231行调用start方法。尝试在之前添加条件语句你打电话来检查用户名和密码是否先为空?此外,take a look at these examples代码片段类似,您可以找到解决方案。