Android Webview POST

前端 未结 4 1534
悲哀的现实
悲哀的现实 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 05:52

    Two ways to load post response in webview:

    1. webview.loadData(): Like what you have posted in your solution. But "content loaded through this mechanism does not have the ability to load content from the network".

    2. webview.postUrl(): Use this if post response needs to load content from the network. (NOTE: only accessible from api-level 5, which means no android 1.6 or lower)


    String postData = "username=my_username&password=my_password";
    webview.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));
    

    (source: http://www.anddev.org/other-coding-problems-f5/webview-posturl-postdata-t14239.html)

提交回复
热议问题