Instead of implement my website as an android app I use my website to show it in the app via webview. I have search and search and found similar question but none give me a solution that works... I want to grab the post data from webview when use a webpage where the user press submit. I got it to work in iOS with swift where i use this solution: Grabbing POST data from UIWebView
What I have tried so far: But this return raw html.
wv.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.d(LOGTAG, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(flag)
{
try {
URL aURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader streamReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuilder response = new StringBuilder();
String inputLine;
while ((inputLine = streamReader.readLine()) != null) {
response.append(inputLine);
}
is.close();
String s = response.toString();
Log.d(LOGTAG, "response" + s);
view.loadUrl(url);
return true;
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
if(url.contains("form.html"))
{
flag = true;
}
}
});
wv.loadUrl(mainUrl);