简体   繁体   English

从WebView Android获取回调数据

[英]Getting callback data from WebView Android

I am using a webview to submit a form and redirect. 我正在使用Webview提交表单并重定向。 When the form is submitted successfully it will print a json response to the console. 成功提交表单后,它将向控制台输出一个json响应。

My question is how can I get the jsonData String from the client? 我的问题是如何从客户端获取jsonData字符串?

chromium: [INFO:CONSOLE(1)] "Callback....jsonData, etc" 铬:[INFO:CONSOLE(1)]“回调.... jsonData等”

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // Insert your code here

                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }
        });

You could extend the WebViewClient class and create a method to intercept the POST request made from clicking the form post button in the HTML in your WebView. 您可以扩展WebViewClient类,并创建一种方法来拦截通过单击WebView中HTML中的表单发布按钮而发出的POST请求。 Then, make the HTTP POST request in the code, rather than in the WebView and parse the results anyway you wish, then refresh the WebView any way you wish at the end of it all. 然后,在代码中而不是在WebView中发出HTTP POST请求,并以您希望的方式解析结果,然后以您希望的任何方式刷新WebView。 There is an example of doing so here: 这里有一个这样做的例子:

https://github.com/KeejOow/android-post-webview/blob/master/PostWebview/postwebview/src/main/java/com/solidsoftware/postwebview/InterceptingWebViewClient.java https://github.com/KeejOow/android-post-webview/blob/master/PostWebview/postwebview/src/main/java/com/solidsoftware/postwebview/InterceptingWebViewClient.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM