0

I just builded an app by ionic-framework. The server side is:

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

All function works fine in the PC chrome browser, authorization pass and request all get correct response.

Request success screen

but once we builded the html5 and angularjs files into apk, function fails.

ionic build android

ionic run android

Got the Error screen by chrome inspect plugin.

There a similar question here. I also tried that way but also can't work.

Client-Via:shouldInterceptRequest

In index.html file there a cross domain js reference also failed.

I find this might relate to shouldInterceptRequest method in SystemWEbViewClient.java

I common few no use code and just direct response the result, finally the js reference successed.

but the auth request still failed

and I am not sure whether this is a best way to solve the problem.

Community
  • 1
  • 1
rickxie
  • 1
  • 1

1 Answers1

0

I just comment the code below which in shouldInterceptRequest method, then it all works.

 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);
    }
}
rickxie
  • 1
  • 1