我想在加载到 webview 之前检查某个 URL 的 HTTP 响应。如果http响应为200,我只想加载webview code
。这是拦截http错误的解决方法。我有以下:
HttpGet httpRequest = new HttpGet( "http://example.com");
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpRequest);
int code = response.getStatusLine().getStatusCode();
但是我遇到了以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo
android.os.NetworkOnMainThreadException
如何解决?或者在 webview 中拦截 http 错误的任何解决方法?谢谢