Ionic requests return 404 only on android, in Chrome it works fine

前端 未结 4 1128
梦如初夏
梦如初夏 2020-12-13 09:00

So, i have cloned the tutorial app repo from ionic. I ran

ionic start conference sidemenu

and then i added a simple $http.get(\'myserver\')

4条回答
  •  情歌与酒
    2020-12-13 09:39

    If the solutions before doesn't work on ionic 3. Thanks @rickie finally a real solution three days of maddness!!! and now is ok. Go to \platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemWebViewClient.java and comment this rows:

    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
          /*  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);
        }
    }
    

提交回复
热议问题