我有一个包含表单(帖子)的html的WebView.单击某个提交按钮时,我会收到JSON响应.
我怎样才能获得这个JSON?
如果我不拦截请求,json会显示在webview上,所以我想我应该使用shouldInterceptRequest(我正在使用API 12),但我不知道如何获取json.
或者也许有更好的方法,比如拦截响应而不是请求?
mWebView.loadUrl(myURL);
isPageLoaded = false; // used because the url is the same for the response
mWebView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest (WebView view, String url) {
if(isPageLoaded){
// get the json
return null;
}
else return super.shouldInterceptRequest(view, url);
}
public void onPageFinished(WebView view, String url) {
isPageLoaded = true;
}
});
谢谢