With the following code, it is possible to send data to a WebView using POST with Android:

 

public void onCreate(Bundle savedInstanceState) {
 
    super.onCreate(savedInstanceState);
 
    WebView wv = new WebView(this);
    setContentView(wv);
 
    String url = "http://www.example.com/login.php";
    String data = "name=Test&password=12345";
 
    wv.postUrl(url, EncodingUtils.getBytes(data, "base64"));
}

This code creates a new WebView and opens the website example.com/login.php in it. When opening the page, the data stored in "data" is passed via POST to the web page.

The code can be used, for example, to implement an automatic login by sending the login data via POST to the login page. In th example, we are sending the variables "name" and "password", but, of course, it is also possible to use the code for any other purpose.

 

全文取自 http://www.askingbox.com/tip/android-programming-send-data-via-post-to-webview-e-g-to-implement-an-automatic-login 


arrow
arrow
    文章標籤
    WEBVIEW POST ANDROID DATA
    全站熱搜
    創作者介紹
    創作者 Frank 的頭像
    Frank

    經驗交流分享與備忘

    Frank 發表在 痞客邦 留言(0) 人氣()