I use webView.loadData () to send a client message, and it displays the contents of the url, my code is:
public static void webview_ClientPost(WebView webView, String url, Collection< Map.Entry<String, String>> postData){ StringBuilder sb = new StringBuilder(); sb.append("<html><head></head>"); sb.append("<body onload='form1.submit()'>"); sb.append(String.format("<form id='form1' action='%s' method='%s'>", url, "post")); for (Map.Entry<String, String> item : postData) { sb.append(String.format("<input name='%s' type='hidden' value='%s' />", item.getKey(), item.getValue())); } sb.append("</form></body></html>"); webView.loadData(sb.toString(), "text/html", "UTF-8"); }
use the webview_ClientPost () function:
Map<String, String> mapParams = new HashMap<String, String>(); mapParams.put("param1", "111"); mapParams.put("param2", "222"); Collection<Map.Entry<String, String>> postData = mapParams.entrySet(); webview_ClientPost(webView1, "http://www.yoursite.com/postreceiver", postData);
HenryChuang May 28 '15 at 9:10 AM 2015-05-28 09:10
source share