我曾两次尝试通过身份验证访问网站,但我不确定我的尝试有什么问题。我会一一列举。有没有人试过这个并让它工作?
这对于 Java Android 程序员来说应该不难理解,我使用 monodroid EDIT也不重要(这很重要,因为我在下面有一个运行良好的 Java 实现)END EDIT。
我正在尝试通过 WebView 访问 SSRS RDL,我需要插入一些通用凭据。
活动:
public static string username = "...";
public static string password = "...";
public static string website = "http://10.0.0.5/Reports";
private WebView webView;
private void setupWebView(int attempt)
{
webView.Settings.JavaScriptEnabled = true;
webView.Settings.BlockNetworkLoads = false;
switch (attempt)
{
case 1:
{
webView.SetHttpAuthUsernamePassword(website, "", username, password);
}break;
case 2:
{
webView.SetWebViewClient(new AuthenticationClient(this));
}break;
}
webView.LoadUrl(website);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
webView = new WebView(this);
setupWebView(1);//1 or 2 depending on what I am testing
// Set our view from the "main" layout resource
SetContentView(webView);
}
}
身份验证客户端:
//DECLARED IN ANOTHER FILE
[Android.Runtime.Register("android/webkit/WebViewClient", DoNotGenerateAcw = true)]
public class AuthenticationClient:WebViewClient
{
private Context _context;
public AuthenticationClient(Context context)
{
_context = context;
}
public override void OnReceivedError(WebView view, ClientError errorCode, string description, string failingUrl)
{
Toast.MakeText(_context, "OnReceivedError: " + errorCode, ToastLength.Long);
//base.OnReceivedError(view, errorCode, description, failingUrl);
}
public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
{
Toast.MakeText(_context, "OnPageStarted: " + url, ToastLength.Long);
//base.OnPageStarted(view, url, favicon);
}
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
Toast.MakeText(_context, "ShouldOverrideUrlLoading: " + url, ToastLength.Long);
view.LoadUrl(url);
return true;
}
public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm)
{
Toast.MakeText(_context, "OnReceivedHttpAuthRequest: " + host, ToastLength.Long);
handler.Proceed(Activity1.username, Activity1.password);
}
}
//END DECLARATION
尝试 1:它甚至不尝试加载页面。我不断收到错误消息:
chromium(18710): external/chromium/net/http/http_auth_gssapi_posix.cc:463: [0821/095922:WARNING:http_auth_gssapi_posix.cc(463)] 无法找到兼容的 GSSAPI 库
尝试 2:不显示单个 toast 消息。
我已经看过: http:
//developer.android.com/reference/android/webkit/WebView.html
Using WebView setHttpAuthUsernamePassword?
WebView.setHttpAuthUsernamePassword() 不工作?
从 Web 应用程序将用户名和密码传递给 SSRS 2005 报告
其他
东西 我现在已经用 Java 完成了它,它工作正常。我仍然需要一个 Mono for Android 解决方案:
public class Android_reporttestActivity extends Activity {
public static String username = "...";
public static String password = "...";
public static String website = "http://10.0.0.5/Reports";
private WebView setupWebView()
{
WebView webView = new WebView(this);
webView.setWebViewClient(
new WebViewClient(){
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)
{
handler.proceed(username,password);
}
}
);
return webView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = setupWebView();
// Set our view from the "main" layout resource
setContentView(webview);
webview.loadUrl(website);
}