Inapp浏览器基本身份验证无效

时间:2016-07-14 08:46:07

标签: android android-webview basic-authentication hybrid-mobile-app mobile-application

我有一个像http://username:password@ipaddress:port//test/test.mjepd.cgi这样的网址。 它实际上是在应用浏览器中流式传输相机。

然而,它适用于笔记本电脑和计算机,而不适用于移动网络视图。 它很简单,无法加载。

通过浏览一些论坛,我发现在app浏览器webview中移动版不支持传递基本身份验证凭据。

对此的任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:0)

选项1:将Authorization标头添加到请求中:

    HashMap<String, String> headers = new HashMap<String, String>();
    String auth = "Basic " + Base64.encodeToString(password.getBytes("UTF-8"), Base64.NO_WRAP);
    headers.put("Authorization", auth);
    webview.loadUrl(url, headers);

选项2:通过回调处理身份验证:

    webview.setWebViewClient(new WebViewClient() {
        public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
            if (realm.equals(expectedRealm) && host.equals(ipaddress)) {
                handler.proceed(username, password);
            } else {
                handler.cancel();
            }
        }
    });

另外:如果你必须使用基本身份验证,请帮个忙,并使用https:;不要以明文形式发送密码。

相关问题