How can I get the JSON response of a POST request in a WebView?

前端 未结 3 2002
我在风中等你
我在风中等你 2020-12-05 03:41

I\'ve got a WebView with html containing a form (post). When clicking some submit button I get a JSON response.

How can I get this JSON?

If I do

3条回答
  •  天涯浪人
    2020-12-05 04:05

    You should override the shouldOverrideUrlLoading method of WebViewClient

    @Override
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
    
        if(flag) { 
    
                URL aURL = new URL(url); 
                URLConnection conn = aURL.openConnection(); 
                conn.connect(); 
                InputStream is = conn.getInputStream(); 
                // read inputstream to get the json..
                ...
                ...
                return true;
        }
    
        return false
    }
    
    @override
    public void onPageFinished (WebView view, String url) {
        if (url contains "form.html") {
            flag = true;
        }
    }
    

    Also take a look at this How do I get the web page contents from a WebView?

提交回复
热议问题