Webview Android中的Http响应

时间:2016-04-18 22:18:18

标签: android webview httpresponse

我的活动加载了webview,如下所示

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set layout
    setContentView(R.layout.activity_webview);
    // get loading view
    loadingView = findViewById(R.id.loadingView);
    loadingView.setVisibility(View.VISIBLE);
    // extract extras from intent
    Intent intent = getIntent();

    // get and setup WebView
    webview = (WebView) findViewById(R.id.webView);
    // implement progress bar
    webview.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            loadingView.setVisibility(View.GONE);
            // if no title was passed in with the intent use the page's title
            if (TextUtils.isEmpty(title)) {
                getSupportActionBar().setDisplayShowTitleEnabled(true);
                getSupportActionBar().setTitle(view.getTitle());
            }
        }

        @SuppressWarnings("deprecation")
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            showErrorAndFinish();
        }

        @TargetApi(Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            // Redirect to deprecated method, so you can use it in all SDK versions
            onReceivedError(view, error.getErrorCode(), error.getDescription().toString(), request.getUrl().toString());
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
            return super.shouldInterceptRequest(view, request);
        }
    });
    // load the url
    webView.loadUrl(url);
}

但是,我需要查看我加载的Url的响应,并根据响应调用另一个API URL。

到目前为止,我已经查看了这个URL Loading QUestion但在5.0下没什么帮助。有关我应该如何处理的任何建议?我应该在shouldOverrideUrlLoading()方法中使用Retrofit吗?

另外,我无法修改我正在加载的URL。

我很感激回应

0 个答案:

没有答案