2016-02-05 51 views
0

我想在網頁視圖加載網頁,但我得到以下異常:找不到文件上的WebView例外 - 當真正的文件存在

java.io.FileNotFoundException: https://fonts.googleapis.com/css?family=Roboto:400,300,500,700,900,700italic 
02-05 18:52:44.497 5263-6265/com.RM W/System.err:  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206) 
02-05 18:52:44.497 5263-6265/com.RM W/System.err:  at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 
02-05 18:52:44.497 5263-6265/com.RM W/System.err:  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25) 
02-05 18:52:44.497 5263-6265/com.RM W/System.err:  at navigationfragments.FragmentWebView$1.shouldInterceptRequest(FragmentWebView.java:124) 
02-05 18:52:44.497 5263-6265/com.RM W/System.err:  at android.webkit.WebViewClient.shouldInterceptRequest(WebViewClient.java:125) 
02-05 18:52:44.498 5263-6265/com.RM W/System.err:  at com.android.webview.chromium.WebViewContentsClientAdapter.shouldInterceptRequest(WebViewContentsClientAdapter.java:297) 
02-05 18:52:44.498 5263-6265/com.RM W/System.err:  at org.chromium.android_webview.AwContents$BackgroundThreadClientImpl.shouldInterceptRequest(AwContents.java:465) 
02-05 18:52:44.498 5263-6265/com.CRM W/System.err:  at org.chromium.android_webview.AwContentsBackgroundThreadClient.shouldInterceptRequestFromNative(AwContentsBackgroundThreadClient.java:38) 

但我驚訝的是,如果我點擊鏈接:

https://fonts.googleapis.com/css?family=Roboto:400,300,500,700,900,700italic

我可以在我的瀏覽器實際加載它。這也會發生在許多opther文件上,通常可以通過瀏覽器訪問。我在這裏錯過什麼?

下面是我的自定義實現:

WebViewClient webViewClient = new WebViewClient() { 

      @Override 
      public void onPageStarted(WebView view, String url, Bitmap favicon) { 
       startAnim(); 
       super.onPageStarted(view, url, favicon); 
      } 


      @Override 
      public void onPageFinished(WebView view, String url) { 
       super.onPageFinished(view, url); 
       if (webView.getProgress() == 100) { 
        stopAnim(); 
       } 
      } 


      @Override 
      public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
       NoNetworkDialog.showNetworkDialog(getActivity()); 

      } 

      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       if (!CheckConnection.isNetworkConnected(getActivity())) { 
        NoNetworkDialog.showNetworkDialog(getActivity()); 
        return false; 
       } else { 
        view.loadUrl(url); 
        return true; 
       } 

      } 

      @Override 
      public WebResourceResponse shouldInterceptRequest(WebView view, String url1) { 

       // if (!CheckConnection.isNetworkConnected(getActivity())) { 
       // NoNetworkDialog.showNetworkDialog(getActivity()); 
       // } else { 
       try { 
        URL url = new URL(url1); 

        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); 


        CookieManager cookieManager = CookieManager.getInstance(); 
        String cookie = cookieManager.getCookie(url.getHost()); 


        urlConnection.setDoOutput(true); 
        urlConnection.setRequestProperty("Cookie", cookie); 
        urlConnection.setRequestProperty("***_USER_AGENT", "***_app"); 
        urlConnection.setRequestMethod("GET"); 

        InputStream in = new BufferedInputStream(urlConnection.getInputStream()); 

        return new WebResourceResponse(urlConnection.getContentType(), "UTF-8", in); 

       } catch (Exception e) { 
        e.printStackTrace(); 

        return null; 
       } 
       // } 
       // return null; 
      } 
     }; 

這裏有其他的URL,我得到這:

https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js

https://www.google.com/jsapi

https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js

回答

1

刪除setDoOutput(),看看它是否有效。你沒有做POST請求,你不需要它。

參考鏈接是here

+0

我明白了,錯誤不再存在。謝了哥們 – User3

相關問題