2016-09-29 51 views
1

我得到了錯誤代碼,如果網頁中的任何錯誤通過setWebViewClient的onReceivedHttpError方法,但是當沒有錯誤任何頁面加載成功或服務器回調我代碼如403然後如何檢查狀態代碼200或403.Android:如何在Webview中獲取狀態碼200 OK?

+0

看到這個http://stackoverflow.com/q/11889020/6482350。據我所知,在Android M之前的設備中沒有好的方法。 – DysaniazzZ

回答

0

您可以在網頁視圖中使用

webView.setWebViewClient(new WebViewClient() { 

@SuppressWarnings("deprecation") 
@Override 
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
    // Handle the error 
} 
@Override 
public void onPageFinished(WebView view, String url) { 
    super.onPageFinished(view, url); 
} 
@Override 
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { 
      // TODO Auto-generated method stub 
      super.onReceivedSslError(view, handler, error); 
      // handle your SSL related error here 
      // handler.proceed(); 
     } 
}); 
+0

thx,但這是請求onError ...我想要的正常狀態代碼,如200. –

+0

是在onReceivedError方法中,您也獲得了errorCode。使用它 –

+0

@ShineLee你明白了我的觀點? –

相關問題