【问题标题】:error of shouldInterceptRequest in *.apk ( Ionic with asp.net mvc OAuth )*.apk 中的 shouldInterceptRequest 错误(带有 asp.net mvc OAuth 的 Ionic)
【发布时间】:2019-08-01 21:46:56
【问题描述】:

我刚刚通过 ionic-framework 构建了一个应用程序。服务器端是:

bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity

所有功能在PC chrome浏览器中运行良好,授权通过和请求都得到正确的响应。

Request success screen

但是一旦我们将 html5 和 angularjs 文件构建到 apk 中,函数就会失败。

离子构建安卓

离子运行安卓

通过 chrome 检查插件获得了Error screen

有一个类似的问题here。我也尝试过这种方式,但也无法工作。

Client-Via:shouldInterceptRequest

在 index.html 文件中有一个跨域 js 引用也失败了。

我发现这可能与 SystemWEbViewClient.java 中的 shouldInterceptRequest 方法有关

我普通的几个没用的代码直接响应结果,终于js引用成功了。

但身份验证请求仍然失败

我不确定这是否是解决问题的最佳方法。

【问题讨论】:

    标签: android angularjs oauth ionic asp.net-web-api


    【解决方案1】:

    我只是在 shouldInterceptRequest 方法中注释下面的代码,然后一切正常。

     public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        try {
            // Check the against the whitelist and lock out access to the WebView directory
            // Changing this will cause problems for your application
        // *********************** below four lines of code commented.-----
        //    if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
        //        LOG.w(TAG, "URL blocked by whitelist: " + url);
                // Results in a 404.
        //        return new WebResourceResponse("text/plain", "UTF-8", null);
        //    }
    
            CordovaResourceApi resourceApi = parentEngine.resourceApi;
            Uri origUri = Uri.parse(url);
            // Allow plugins to intercept WebView requests.
            Uri remappedUri = resourceApi.remapUri(origUri);
    
            if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
                CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
                return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
            }
            // If we don't need to special-case the request, let the browser load it.
            return null;
        } catch (IOException e) {
            if (!(e instanceof FileNotFoundException)) {
                LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
            }
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2015-10-07
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多