Android Webview POST

前端 未结 4 1533
悲哀的现实
悲哀的现实 2020-11-28 05:22

I am trying to accomplish something quite simple, yet I have found no good documentation on this. I have a webView, and I need to load a page in it that requires POST data.

4条回答
  •  暖寄归人
    2020-11-28 06:19

    I use webView.loadData() to do client post, and it will display content of url, my code :

    public static void webview_ClientPost(WebView webView, String url, Collection< Map.Entry> postData){
        StringBuilder sb = new StringBuilder();
    
        sb.append("");
        sb.append("");
        sb.append(String.format("
    ", url, "post")); for (Map.Entry item : postData) { sb.append(String.format("", item.getKey(), item.getValue())); } sb.append(""); webView.loadData(sb.toString(), "text/html", "UTF-8"); }

    use function webview_ClientPost() :

    Map mapParams = new HashMap();      
    mapParams.put("param1", "111");
    mapParams.put("param2", "222");
    
    Collection> postData = mapParams.entrySet();
    
    webview_ClientPost(webView1, "http://www.yoursite.com/postreceiver", postData);
    

提交回复
热议问题